net-ldap 0.11 → 0.16.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.

Potentially problematic release.


This version of net-ldap might be problematic. Click here for more details.

Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +15 -0
  3. data/.rubocop_todo.yml +471 -180
  4. data/.travis.yml +10 -5
  5. data/Contributors.rdoc +1 -0
  6. data/History.rdoc +60 -0
  7. data/README.rdoc +18 -11
  8. data/Rakefile +0 -1
  9. data/lib/net/ber/ber_parser.rb +4 -4
  10. data/lib/net/ber/core_ext/array.rb +1 -1
  11. data/lib/net/ber/core_ext/integer.rb +1 -1
  12. data/lib/net/ber/core_ext/string.rb +1 -1
  13. data/lib/net/ber.rb +37 -5
  14. data/lib/net/ldap/auth_adapter/gss_spnego.rb +41 -0
  15. data/lib/net/ldap/auth_adapter/sasl.rb +62 -0
  16. data/lib/net/ldap/auth_adapter/simple.rb +34 -0
  17. data/lib/net/ldap/auth_adapter.rb +29 -0
  18. data/lib/net/ldap/connection.rb +197 -187
  19. data/lib/net/ldap/dataset.rb +2 -2
  20. data/lib/net/ldap/dn.rb +4 -5
  21. data/lib/net/ldap/entry.rb +4 -5
  22. data/lib/net/ldap/error.rb +36 -1
  23. data/lib/net/ldap/filter.rb +6 -6
  24. data/lib/net/ldap/pdu.rb +26 -2
  25. data/lib/net/ldap/version.rb +1 -1
  26. data/lib/net/ldap.rb +189 -75
  27. data/lib/net/snmp.rb +18 -18
  28. data/net-ldap.gemspec +4 -2
  29. data/script/changelog +47 -0
  30. data/script/generate-fixture-ca +48 -0
  31. data/script/install-openldap +67 -44
  32. data/test/ber/core_ext/test_array.rb +1 -1
  33. data/test/ber/test_ber.rb +11 -3
  34. data/test/fixtures/ca/ca.info +4 -0
  35. data/test/fixtures/ca/cacert.pem +24 -0
  36. data/test/fixtures/ca/cakey.pem +190 -0
  37. data/test/fixtures/openldap/slapd.conf.ldif +1 -1
  38. data/test/integration/test_add.rb +1 -1
  39. data/test/integration/test_ber.rb +1 -1
  40. data/test/integration/test_bind.rb +220 -10
  41. data/test/integration/test_delete.rb +1 -1
  42. data/test/integration/test_open.rb +1 -1
  43. data/test/integration/test_password_modify.rb +80 -0
  44. data/test/integration/test_search.rb +1 -1
  45. data/test/support/vm/openldap/README.md +35 -3
  46. data/test/support/vm/openldap/Vagrantfile +1 -0
  47. data/test/test_auth_adapter.rb +15 -0
  48. data/test/test_dn.rb +3 -3
  49. data/test/test_filter.rb +4 -4
  50. data/test/test_filter_parser.rb +4 -0
  51. data/test/test_helper.rb +10 -2
  52. data/test/test_ldap.rb +64 -10
  53. data/test/test_ldap_connection.rb +115 -28
  54. data/test/test_ldif.rb +11 -11
  55. data/test/test_search.rb +2 -2
  56. data/test/test_snmp.rb +4 -4
  57. data/testserver/ldapserver.rb +11 -12
  58. metadata +50 -8
  59. data/test/fixtures/cacert.pem +0 -20
data/.travis.yml CHANGED
@@ -1,26 +1,31 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 1.9.3
4
3
  - 2.0.0
5
- - 2.1.2
4
+ - 2.1
5
+ - 2.2
6
6
  # optional
7
+ - ruby-head
7
8
  - jruby-19mode
8
- - rbx-19mode
9
+ - jruby-head
9
10
  - rbx-2
10
11
 
11
12
  env:
12
13
  - INTEGRATION=openldap
13
14
 
15
+ before_install:
16
+ - gem update bundler
17
+
14
18
  install:
15
- - if [ "$INTEGRATION" = "openldap" ]; then ./script/install-openldap; fi
19
+ - if [ "$INTEGRATION" = "openldap" ]; then sudo script/install-openldap; fi
16
20
  - bundle install
17
21
 
18
22
  script: bundle exec rake ci
19
23
 
20
24
  matrix:
21
25
  allow_failures:
26
+ - rvm: ruby-head
22
27
  - rvm: jruby-19mode
23
- - rvm: rbx-19mode
28
+ - rvm: jruby-head
24
29
  - rvm: rbx-2
25
30
  fast_finish: true
26
31
 
data/Contributors.rdoc CHANGED
@@ -22,3 +22,4 @@ Contributions since:
22
22
  * David J. Lee (DavidJLee)
23
23
  * Cody Cutrer (ccutrer)
24
24
  * WoodsBagotAndreMarquesLee
25
+ * Rufus Post (mynameisrufus)
data/History.rdoc CHANGED
@@ -1,3 +1,63 @@
1
+ === Net::LDAP 0.16.0
2
+
3
+ * Sasl fix {#281}[https://github.com/ruby-ldap/ruby-net-ldap/pull/281]
4
+ * enable TLS hostname validation {#279}[https://github.com/ruby-ldap/ruby-net-ldap/pull/279]
5
+ * update rubocop to 0.42.0 {#278}[https://github.com/ruby-ldap/ruby-net-ldap/pull/278]
6
+
7
+ === Net::LDAP 0.15.0
8
+
9
+ * Respect connect_timeout when establishing SSL connections {#273}[https://github.com/ruby-ldap/ruby-net-ldap/pull/273]
10
+
11
+ === Net::LDAP 0.14.0
12
+
13
+ * Normalize the encryption parameter passed to the LDAP constructor {#264}[https://github.com/ruby-ldap/ruby-net-ldap/pull/264]
14
+ * Update Docs: Net::LDAP now requires ruby >= 2 {#261}[https://github.com/ruby-ldap/ruby-net-ldap/pull/261]
15
+ * fix symbol proc {#255}[https://github.com/ruby-ldap/ruby-net-ldap/pull/255]
16
+ * fix trailing commas {#256}[https://github.com/ruby-ldap/ruby-net-ldap/pull/256]
17
+ * fix deprecated hash methods {#254}[https://github.com/ruby-ldap/ruby-net-ldap/pull/254]
18
+ * fix space after comma {#253}[https://github.com/ruby-ldap/ruby-net-ldap/pull/253]
19
+ * fix space inside brackets {#252}[https://github.com/ruby-ldap/ruby-net-ldap/pull/252]
20
+ * Rubocop style fixes {#249}[https://github.com/ruby-ldap/ruby-net-ldap/pull/249]
21
+ * Lazy initialize Net::LDAP::Connection's internal socket {#235}[https://github.com/ruby-ldap/ruby-net-ldap/pull/235]
22
+ * Support for rfc3062 Password Modify, closes #163 {#178}[https://github.com/ruby-ldap/ruby-net-ldap/pull/178]
23
+
24
+ === Net::LDAP 0.13.0
25
+
26
+ Avoid this release for because of an backwards incompatibility in how encryption
27
+ is initialized https://github.com/ruby-ldap/ruby-net-ldap/pull/264. We did not
28
+ yank it because people have already worked around it.
29
+
30
+ * Set a connect_timeout for the creation of a socket {#243}[https://github.com/ruby-ldap/ruby-net-ldap/pull/243]
31
+ * Update bundler before installing gems with bundler {#245}[https://github.com/ruby-ldap/ruby-net-ldap/pull/245]
32
+ * Net::LDAP#encryption accepts string {#239}[https://github.com/ruby-ldap/ruby-net-ldap/pull/239]
33
+ * Adds correct UTF-8 encoding to Net::BER::BerIdentifiedString {#242}[https://github.com/ruby-ldap/ruby-net-ldap/pull/242]
34
+ * Remove 2.3.0-preview since ruby-head already is included {#241}[https://github.com/ruby-ldap/ruby-net-ldap/pull/241]
35
+ * Drop support for ruby 1.9.3 {#240}[https://github.com/ruby-ldap/ruby-net-ldap/pull/240]
36
+ * Fixed capitalization of StartTLSError {#234}[https://github.com/ruby-ldap/ruby-net-ldap/pull/234]
37
+
38
+ === Net::LDAP 0.12.1
39
+
40
+ * Whitespace formatting cleanup {#236}[https://github.com/ruby-ldap/ruby-net-ldap/pull/236]
41
+ * Set operation result if LDAP server is not accessible {#232}[https://github.com/ruby-ldap/ruby-net-ldap/pull/232]
42
+
43
+ === Net::LDAP 0.12.0
44
+
45
+ * DRY up connection handling logic {#224}[https://github.com/ruby-ldap/ruby-net-ldap/pull/224]
46
+ * Define auth adapters {#226}[https://github.com/ruby-ldap/ruby-net-ldap/pull/226]
47
+ * add slash to attribute value filter {#225}[https://github.com/ruby-ldap/ruby-net-ldap/pull/225]
48
+ * Add the ability to provide a list of hosts for a connection {#223}[https://github.com/ruby-ldap/ruby-net-ldap/pull/223]
49
+ * Specify the port of LDAP server by giving INTEGRATION_PORT {#221}[https://github.com/ruby-ldap/ruby-net-ldap/pull/221]
50
+ * Correctly set BerIdentifiedString values to UTF-8 {#212}[https://github.com/ruby-ldap/ruby-net-ldap/pull/212]
51
+ * Raise Net::LDAP::ConnectionRefusedError when new connection is refused. {#213}[https://github.com/ruby-ldap/ruby-net-ldap/pull/213]
52
+ * obscure auth password upon #inspect, added test, closes #216 {#217}[https://github.com/ruby-ldap/ruby-net-ldap/pull/217]
53
+ * Fixing incorrect error class name {#207}[https://github.com/ruby-ldap/ruby-net-ldap/pull/207]
54
+ * Travis update {#205}[https://github.com/ruby-ldap/ruby-net-ldap/pull/205]
55
+ * Remove obsolete rbx-19mode from Travis {#204}[https://github.com/ruby-ldap/ruby-net-ldap/pull/204]
56
+ * mv "sudo" from script/install-openldap to .travis.yml {#199}[https://github.com/ruby-ldap/ruby-net-ldap/pull/199]
57
+ * Remove meaningless shebang {#200}[https://github.com/ruby-ldap/ruby-net-ldap/pull/200]
58
+ * Fix Travis CI build {#202}[https://github.com/ruby-ldap/ruby-net-ldap/pull/202]
59
+ * README.rdoc: fix travis link {#195}[https://github.com/ruby-ldap/ruby-net-ldap/pull/195]
60
+
1
61
  === Net::LDAP 0.11
2
62
  * Major enhancements:
3
63
  * #183 Specific errors subclassing Net::LDAP::Error
data/README.rdoc CHANGED
@@ -1,4 +1,4 @@
1
- = Net::LDAP for Ruby {<img src="https://travis-ci.org/ruby-ldap/ruby-net-ldap.png" />}[https://travis-ci.org/github/ruby-net-ldap]
1
+ = Net::LDAP for Ruby {<img src="https://travis-ci.org/ruby-ldap/ruby-net-ldap.png" />}[https://travis-ci.org/ruby-ldap/ruby-net-ldap]
2
2
 
3
3
  == Description
4
4
 
@@ -25,7 +25,7 @@ See Net::LDAP for documentation and usage samples.
25
25
 
26
26
  == Requirements
27
27
 
28
- Net::LDAP requires a Ruby 1.9.3 compatible interpreter or better.
28
+ Net::LDAP requires a Ruby 2.0.0 compatible interpreter or better.
29
29
 
30
30
  == Install
31
31
 
@@ -37,6 +37,14 @@ sources.
37
37
 
38
38
  Simply require either 'net-ldap' or 'net/ldap'.
39
39
 
40
+ == Extensions
41
+
42
+ This library focuses on the core LDAP RFCs referenced in the description.
43
+ However, we recognize there are commonly used extensions to the spec that are
44
+ useful. If there is another library which handles it, we list it here.
45
+
46
+ * {resolv-srv}[https://rubygems.org/gems/resolv-srv]: Support RFC2782 SRV record lookup and failover
47
+
40
48
  == Develop
41
49
 
42
50
  This task will run the test suite and the
@@ -44,21 +52,20 @@ This task will run the test suite and the
44
52
 
45
53
  rake rubotest
46
54
 
47
- To run the integration tests against an LDAP server:
48
-
49
- cd test/support/vm/openldap
50
- vagrant up
51
- cd ../../../..
52
- INTEGRATION=openldap bundle exec rake rubotest
55
+ CI takes too long? If your local box supports
56
+ {Vagrant}[https://www.vagrantup.com/], you can run most of the tests
57
+ in a VM on your local box. For more details and setup instructions, see
58
+ {test/support/vm/openldap/README.md}[https://github.com/ruby-ldap/ruby-net-ldap/tree/master/test/support/vm/openldap/README.md]
53
59
 
54
60
  == Release
55
61
 
56
62
  This section is for gem maintainers to cut a new version of the gem.
57
63
 
64
+ * Check out a new branch `release-VERSION`
58
65
  * Update lib/net/ldap/version.rb to next version number X.X.X following {semver}(http://semver.org/).
59
- * Update `History.rdoc`. Get latest changes with `git log --oneline vLAST_RELEASE..HEAD | grep Merge`
60
-
61
- * On the master branch, run `script/release`
66
+ * Update `History.rdoc`. Get latest changes with `script/changelog`
67
+ * Open a pull request with these changes for review
68
+ * After merging, on the master branch, run `script/release`
62
69
 
63
70
  :include: Contributors.rdoc
64
71
 
data/Rakefile CHANGED
@@ -1,4 +1,3 @@
1
- #!/usr/bin/env rake
2
1
  # -*- ruby encoding: utf-8 -*-
3
2
  # vim: syntax=ruby
4
3
 
@@ -14,7 +14,7 @@ module Net::BER::BERParser
14
14
  }
15
15
  constructed = {
16
16
  16 => :array,
17
- 17 => :array
17
+ 17 => :array,
18
18
  }
19
19
  universal = { :primitive => primitive, :constructed => constructed }
20
20
 
@@ -172,10 +172,10 @@ module Net::BER::BERParser
172
172
  yield id, content_length if block_given?
173
173
 
174
174
  if -1 == content_length
175
- raise Net::BER::BerError, "Indeterminite BER content length not implemented."
176
- else
177
- data = read(content_length)
175
+ raise Net::BER::BerError,
176
+ "Indeterminite BER content length not implemented."
178
177
  end
178
+ data = read(content_length)
179
179
 
180
180
  parse_ber_object(syntax, id, data)
181
181
  end
@@ -89,7 +89,7 @@ module Net::BER::Extensions::Array
89
89
  #if our array does not contain at least one array then wrap it in an array before going forward
90
90
  ary = self[0].kind_of?(Array) ? self : [self]
91
91
  ary = ary.collect do |control_sequence|
92
- control_sequence.collect{|element| element.to_ber}.to_ber_sequence.reject_empty_ber_arrays
92
+ control_sequence.collect(&:to_ber).to_ber_sequence.reject_empty_ber_arrays
93
93
  end
94
94
  ary.to_ber_sequence.reject_empty_ber_arrays
95
95
  end
@@ -20,7 +20,7 @@ module Net::BER::Extensions::Integer
20
20
  if self <= 127
21
21
  [self].pack('C')
22
22
  else
23
- i = [self].pack('N').sub(/^[\0]+/,"")
23
+ i = [self].pack('N').sub(/^[\0]+/, "")
24
24
  [0x80 + i.length].pack('C') + i
25
25
  end
26
26
  end
@@ -75,6 +75,6 @@ module Net::BER::Extensions::String
75
75
  end
76
76
 
77
77
  def reject_empty_ber_arrays
78
- self.gsub(/0\000/n,'')
78
+ self.gsub(/0\000/n, '')
79
79
  end
80
80
  end
data/lib/net/ber.rb CHANGED
@@ -106,6 +106,7 @@ module Net # :nodoc:
106
106
  # <tr><th>CHARACTER STRING</th><th>C</th><td>29: 61 (0x3d, 0b00111101)</td></tr>
107
107
  # <tr><th>BMPString</th><th>P</th><td>30: 30 (0x1e, 0b00011110)</td></tr>
108
108
  # <tr><th>BMPString</th><th>C</th><td>30: 62 (0x3e, 0b00111110)</td></tr>
109
+ # <tr><th>ExtendedResponse</th><th>C</th><td>107: 139 (0x8b, 0b010001011)</td></tr>
109
110
  # </table>
110
111
  module BER
111
112
  VERSION = Net::LDAP::VERSION
@@ -234,7 +235,7 @@ module Net # :nodoc:
234
235
  # TODO 20100327 AZ: Should we be allocating an array of 256 values
235
236
  # that will either be +nil+ or an object type symbol, or should we
236
237
  # allocate an empty Hash since unknown values return +nil+ anyway?
237
- out = [ nil ] * 256
238
+ out = [nil] * 256
238
239
  syntax.each do |tag_class_id, encodings|
239
240
  tag_class = TAG_CLASS[tag_class_id]
240
241
  encodings.each do |encoding_id, classes|
@@ -269,7 +270,7 @@ class Net::BER::BerIdentifiedOid
269
270
 
270
271
  def initialize(oid)
271
272
  if oid.is_a?(String)
272
- oid = oid.split(/\./).map {|s| s.to_i }
273
+ oid = oid.split(/\./).map(&:to_i)
273
274
  end
274
275
  @value = oid
275
276
  end
@@ -293,12 +294,43 @@ end
293
294
 
294
295
  ##
295
296
  # A String object with a BER identifier attached.
297
+ #
296
298
  class Net::BER::BerIdentifiedString < String
297
299
  attr_accessor :ber_identifier
300
+
301
+ # The binary data provided when parsing the result of the LDAP search
302
+ # has the encoding 'ASCII-8BIT' (which is basically 'BINARY', or 'unknown').
303
+ #
304
+ # This is the kind of a backtrace showing how the binary `data` comes to
305
+ # BerIdentifiedString.new(data):
306
+ #
307
+ # @conn.read_ber(syntax)
308
+ # -> StringIO.new(self).read_ber(syntax), i.e. included from module
309
+ # -> Net::BER::BERParser.read_ber(syntax)
310
+ # -> (private)Net::BER::BERParser.parse_ber_object(syntax, id, data)
311
+ #
312
+ # In the `#parse_ber_object` method `data`, according to its OID, is being
313
+ # 'casted' to one of the Net::BER:BerIdentifiedXXX classes.
314
+ #
315
+ # As we are using LDAP v3 we can safely assume that the data is encoded
316
+ # in UTF-8 and therefore the only thing to be done when instantiating is to
317
+ # switch the encoding from 'ASCII-8BIT' to 'UTF-8'.
318
+ #
319
+ # Unfortunately, there are some ActiveDirectory specific attributes
320
+ # (like `objectguid`) that should remain binary (do they really?).
321
+ # Using the `#valid_encoding?` we can trap this cases. Special cases like
322
+ # Japanese, Korean, etc. encodings might also profit from this. However
323
+ # I have no clue how this encodings function.
298
324
  def initialize args
299
- super args
300
- # LDAP uses UTF-8 encoded strings
301
- self.encode('UTF-8') if self.respond_to?(:encoding) rescue self
325
+ super
326
+ #
327
+ # Check the encoding of the newly created String and set the encoding
328
+ # to 'UTF-8' (NOTE: we do NOT change the bytes, but only set the
329
+ # encoding to 'UTF-8').
330
+ return unless encoding == Encoding::BINARY
331
+ current_encoding = encoding
332
+ force_encoding('UTF-8')
333
+ force_encoding(current_encoding) unless valid_encoding?
302
334
  end
303
335
  end
304
336
 
@@ -0,0 +1,41 @@
1
+ require 'net/ldap/auth_adapter'
2
+ require 'net/ldap/auth_adapter/sasl'
3
+
4
+ module Net
5
+ class LDAP
6
+ module AuthAdapers
7
+ #--
8
+ # PROVISIONAL, only for testing SASL implementations. DON'T USE THIS YET.
9
+ # Uses Kohei Kajimoto's Ruby/NTLM. We have to find a clean way to
10
+ # integrate it without introducing an external dependency.
11
+ #
12
+ # This authentication method is accessed by calling #bind with a :method
13
+ # parameter of :gss_spnego. It requires :username and :password
14
+ # attributes, just like the :simple authentication method. It performs a
15
+ # GSS-SPNEGO authentication with the server, which is presumed to be a
16
+ # Microsoft Active Directory.
17
+ #++
18
+ class GSS_SPNEGO < Net::LDAP::AuthAdapter
19
+ def bind(auth)
20
+ require 'ntlm'
21
+
22
+ user, psw = [auth[:username] || auth[:dn], auth[:password]]
23
+ raise Net::LDAP::BindingInformationInvalidError, "Invalid binding information" unless (user && psw)
24
+
25
+ nego = proc do |challenge|
26
+ t2_msg = NTLM::Message.parse(challenge)
27
+ t3_msg = t2_msg.response({ :user => user, :password => psw },
28
+ { :ntlmv2 => true })
29
+ t3_msg.serialize
30
+ end
31
+
32
+ Net::LDAP::AuthAdapter::Sasl.new(@connection).bind \
33
+ :method => :sasl,
34
+ :mechanism => "GSS-SPNEGO",
35
+ :initial_credential => NTLM::Message::Type1.new.serialize,
36
+ :challenge_response => nego
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,62 @@
1
+ require 'net/ldap/auth_adapter'
2
+
3
+ module Net
4
+ class LDAP
5
+ class AuthAdapter
6
+ class Sasl < Net::LDAP::AuthAdapter
7
+ MAX_SASL_CHALLENGES = 10
8
+
9
+ #--
10
+ # Required parameters: :mechanism, :initial_credential and
11
+ # :challenge_response
12
+ #
13
+ # Mechanism is a string value that will be passed in the SASL-packet's
14
+ # "mechanism" field.
15
+ #
16
+ # Initial credential is most likely a string. It's passed in the initial
17
+ # BindRequest that goes to the server. In some protocols, it may be empty.
18
+ #
19
+ # Challenge-response is a Ruby proc that takes a single parameter and
20
+ # returns an object that will typically be a string. The
21
+ # challenge-response block is called when the server returns a
22
+ # BindResponse with a result code of 14 (saslBindInProgress). The
23
+ # challenge-response block receives a parameter containing the data
24
+ # returned by the server in the saslServerCreds field of the LDAP
25
+ # BindResponse packet. The challenge-response block may be called multiple
26
+ # times during the course of a SASL authentication, and each time it must
27
+ # return a value that will be passed back to the server as the credential
28
+ # data in the next BindRequest packet.
29
+ #++
30
+ def bind(auth)
31
+ mech, cred, chall = auth[:mechanism], auth[:initial_credential],
32
+ auth[:challenge_response]
33
+ raise Net::LDAP::BindingInformationInvalidError, "Invalid binding information" unless (mech && cred && chall)
34
+
35
+ message_id = @connection.next_msgid
36
+
37
+ n = 0
38
+ loop do
39
+ sasl = [mech.to_ber, cred.to_ber].to_ber_contextspecific(3)
40
+ request = [
41
+ Net::LDAP::Connection::LdapVersion.to_ber, "".to_ber, sasl
42
+ ].to_ber_appsequence(Net::LDAP::PDU::BindRequest)
43
+
44
+ @connection.send(:write, request, nil, message_id)
45
+ pdu = @connection.queued_read(message_id)
46
+
47
+ if !pdu || pdu.app_tag != Net::LDAP::PDU::BindResult
48
+ raise Net::LDAP::NoBindResultError, "no bind result"
49
+ end
50
+
51
+ return pdu unless pdu.result_code == Net::LDAP::ResultCodeSaslBindInProgress
52
+ raise Net::LDAP::SASLChallengeOverflowError, "sasl-challenge overflow" if ((n += 1) > MAX_SASL_CHALLENGES)
53
+
54
+ cred = chall.call(pdu.result_server_sasl_creds)
55
+ end
56
+
57
+ raise Net::LDAP::SASLChallengeOverflowError, "why are we here?"
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,34 @@
1
+ require 'net/ldap/auth_adapter'
2
+
3
+ module Net
4
+ class LDAP
5
+ class AuthAdapter
6
+ class Simple < AuthAdapter
7
+ def bind(auth)
8
+ user, psw = if auth[:method] == :simple
9
+ [auth[:username] || auth[:dn], auth[:password]]
10
+ else
11
+ ["", ""]
12
+ end
13
+
14
+ raise Net::LDAP::BindingInformationInvalidError, "Invalid binding information" unless (user && psw)
15
+
16
+ message_id = @connection.next_msgid
17
+ request = [
18
+ Net::LDAP::Connection::LdapVersion.to_ber, user.to_ber,
19
+ psw.to_ber_contextspecific(0)
20
+ ].to_ber_appsequence(Net::LDAP::PDU::BindRequest)
21
+
22
+ @connection.send(:write, request, nil, message_id)
23
+ pdu = @connection.queued_read(message_id)
24
+
25
+ if !pdu || pdu.app_tag != Net::LDAP::PDU::BindResult
26
+ raise Net::LDAP::NoBindResultError, "no bind result"
27
+ end
28
+
29
+ pdu
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,29 @@
1
+ module Net
2
+ class LDAP
3
+ class AuthAdapter
4
+ def self.register(names, adapter)
5
+ names = Array(names)
6
+ @adapters ||= {}
7
+ names.each do |name|
8
+ @adapters[name] = adapter
9
+ end
10
+ end
11
+
12
+ def self.[](name)
13
+ a = @adapters[name]
14
+ if a.nil?
15
+ raise Net::LDAP::AuthMethodUnsupportedError, "Unsupported auth method (#{name})"
16
+ end
17
+ return a
18
+ end
19
+
20
+ def initialize(conn)
21
+ @connection = conn
22
+ end
23
+
24
+ def bind
25
+ raise "bind method must be overwritten"
26
+ end
27
+ end
28
+ end
29
+ end