resolv-srv 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b52d06ac3497bab2fa8922e14a2c2bcb1d9fb639
4
- data.tar.gz: b3af0aaa18a42710a43312089286807e1b75fe0d
3
+ metadata.gz: 71c1885d00053bc7b796987ff3d563544b1e45f5
4
+ data.tar.gz: 7b46e5dc1a3328c4ea88ac5ccd86c37d22ad26a1
5
5
  SHA512:
6
- metadata.gz: 039252fd5c46c66b71ca38b444c364ca93294b00e151f1ced4b99a66ae73b3e8652c6e3234570266ef1ec00e915e3a84c4a33fd20dddd77e3e54505745bf1018
7
- data.tar.gz: 86e6293c859759d2c3b43a2db1e1428d002a0f6e1d932242e102daa563b6c9c6c4c473c4c05e79c8e2f672adb4dadb6e69ea7340d18f4c054921696ce6fbd5fe
6
+ metadata.gz: 54fdd1d75c98f38cbc8309c2f44a76a5a15e77480da88103d962a4696a206ca7986c3fd124caa3243e2d8e50d0f5501d8e5a1ef91006a04f34acab613e696afc
7
+ data.tar.gz: 0d85e121d2477bade2b0ba033430a73a6252c6584ffaf3fbcdd7ee040dddb1875dbc205d21bd280302e58396a09e144022e4ac87ca78cccf3eca2ca48069297d
data/NEWS.md CHANGED
@@ -6,6 +6,10 @@ detailed information is available in the rest of the documentation.
6
6
  **NOTE:** Date stamps in the following entries are in YYYY/MM/DD format.
7
7
 
8
8
 
9
+ ## v0.0.2 (2016/01/05)
10
+
11
+ * Include an improved example
12
+
9
13
  ## v0.0.1 (2015/08/03)
10
14
 
11
15
  * Birthday
data/README.md CHANGED
@@ -24,7 +24,8 @@ and iterate over SRV records according to their relative priorities and weights.
24
24
  ## Synopsis
25
25
 
26
26
  Look up your user information in Active Directory (assumes `/etc/ssl/certs`
27
- contains the internal CA certificate for the domain):
27
+ contains the internal CA certificate for the domain and that net-ldap v0.12.0 or
28
+ greater is used):
28
29
 
29
30
  ```ruby
30
31
  #!/usr/bin/env ruby
@@ -33,34 +34,41 @@ require 'net/ldap'
33
34
  require 'pp'
34
35
  require 'resolv-srv'
35
36
 
36
- def search_ldap(domain, username, password, search_args = {})
37
- base = domain.split('.').map { |n| "dc=#{n}" }.join(',')
38
- Resolv::DNS.open do |dns|
39
- dns.each_srv_resource('ldap', 'tcp', domain) do |srv|
40
- begin
41
- Net::LDAP.open(
42
- host: srv.target.to_s,
43
- port: srv.port,
44
- base: base,
45
- auth: {
46
- method: :simple,
47
- username: username,
48
- password: password,
49
- },
50
- encryption: {
51
- method: :start_tls,
52
- tls_options: { ca_path: '/etc/ssl/certs' }
53
- },
54
- ) do |ldap|
55
- return ldap.search(search_args)
56
- end
57
- rescue Net::LDAP::Error, OpenSSL::SSL::SSLError
58
- puts "Failed with host #{srv.target} on port #{srv.port}: #{$!}"
37
+ class LDAPServerList
38
+ include Enumerable
39
+
40
+ def initialize(domain)
41
+ @domain = domain
42
+ end
43
+
44
+ def each
45
+ Resolv::DNS.open do |dns|
46
+ dns.each_srv_resource('ldap', 'tcp', @domain) do |srv|
47
+ yield(srv.target.to_s, srv.port)
59
48
  end
60
49
  end
61
50
  end
62
51
  end
63
52
 
53
+ def search_ldap(domain, username, password, search_args = {})
54
+ base = domain.split('.').map { |n| "dc=#{n}" }.join(',')
55
+ Net::LDAP.open(
56
+ hosts: LDAPServerList.new(domain),
57
+ base: base,
58
+ auth: {
59
+ method: :simple,
60
+ username: username,
61
+ password: password,
62
+ },
63
+ encryption: {
64
+ method: :start_tls,
65
+ tls_options: { ca_path: '/etc/ssl/certs' }
66
+ },
67
+ ) do |ldap|
68
+ return ldap.search(search_args)
69
+ end
70
+ end
71
+
64
72
  print 'AD Domain: '
65
73
  domain = gets.chomp
66
74
  print 'AD Username: '
@@ -75,6 +83,7 @@ pp search_ldap(
75
83
  password,
76
84
  filter: "sAMAccountName=#{username}"
77
85
  )
86
+
78
87
  ```
79
88
 
80
89
  ## Requirements
@@ -0,0 +1,55 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'net/ldap'
4
+ require 'pp'
5
+ require 'resolv-srv'
6
+
7
+ class LDAPServerList
8
+ include Enumerable
9
+
10
+ def initialize(domain)
11
+ @domain = domain
12
+ end
13
+
14
+ def each
15
+ Resolv::DNS.open do |dns|
16
+ dns.each_srv_resource('ldap', 'tcp', @domain) do |srv|
17
+ yield(srv.target.to_s, srv.port)
18
+ end
19
+ end
20
+ end
21
+ end
22
+
23
+ def search_ldap(domain, username, password, search_args = {})
24
+ base = domain.split('.').map { |n| "dc=#{n}" }.join(',')
25
+ Net::LDAP.open(
26
+ hosts: LDAPServerList.new(domain),
27
+ base: base,
28
+ auth: {
29
+ method: :simple,
30
+ username: username,
31
+ password: password,
32
+ },
33
+ encryption: {
34
+ method: :start_tls,
35
+ tls_options: { ca_path: '/etc/ssl/certs' }
36
+ },
37
+ ) do |ldap|
38
+ return ldap.search(search_args)
39
+ end
40
+ end
41
+
42
+ print 'AD Domain: '
43
+ domain = gets.chomp
44
+ print 'AD Username: '
45
+ username = gets.chomp
46
+ print "AD Password (#{username}): "
47
+ password = ($stdin.tty? ? $stdin.noecho(&:gets) : $stdin.gets).chomp
48
+ puts
49
+
50
+ pp search_ldap(
51
+ domain,
52
+ "#{username}@#{domain}",
53
+ password,
54
+ filter: "sAMAccountName=#{username}"
55
+ )
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: resolv-srv
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Bopp
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-03 00:00:00.000000000 Z
11
+ date: 2016-01-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -138,6 +138,7 @@ files:
138
138
  - NEWS.md
139
139
  - README.md
140
140
  - Rakefile
141
+ - examples/active-directory.rb
141
142
  - lib/resolv-srv.rb
142
143
  - spec/each_srv_resource_spec.rb
143
144
  homepage: https://github.com/javanthropus/resolv-srv