@@ -308,6 +308,7 @@ class LdapError < StandardError; end
308308 DefaultPort = 389
309309 DefaultAuth = { :method => :anonymous }
310310 DefaultTreebase = "dc=com"
311+ DefaultForceNoPage = false
311312
312313 StartTlsOid = "1.3.6.1.4.1.1466.20037"
313314
@@ -370,6 +371,8 @@ def self.result2string(code) #:nodoc:
370371 # specifying the Hash {:method => :simple_tls}. There is a fairly large
371372 # range of potential values that may be given for this parameter. See
372373 # #encryption for details.
374+ # * :force_no_page => Set to true to prevent paged results even if your
375+ # server says it supports them. This is a fix for MS Active Directory
373376 #
374377 # Instantiating a Net::LDAP object does <i>not</i> result in network
375378 # traffic to the LDAP server. It simply stores the connection and binding
@@ -380,6 +383,7 @@ def initialize(args = {})
380383 @verbose = false # Make this configurable with a switch on the class.
381384 @auth = args [ :auth ] || DefaultAuth
382385 @base = args [ :base ] || DefaultTreebase
386+ @force_no_page = args [ :force_no_page ] || DefaultForceNoPage
383387 encryption args [ :encryption ] # may be nil
384388
385389 if pr = @auth [ :password ] and pr . respond_to? ( :call )
@@ -1092,6 +1096,10 @@ def search_subschema_entry
10921096 # MUST refactor the root_dse call out.
10931097 #++
10941098 def paged_searches_supported?
1099+ # active directory returns that it supports paged results. However
1100+ # it returns binary data in the rfc2696_cookie which throws an
1101+ # encoding exception breaking searching.
1102+ return false if @force_no_page
10951103 @server_caps ||= search_root_dse
10961104 @server_caps [ :supportedcontrol ] . include? ( Net ::LDAP ::LdapControls ::PagedResults )
10971105 end
@@ -1387,6 +1395,10 @@ def search(args = {})
13871395 search_attributes . to_ber_sequence
13881396 ] . to_ber_appsequence ( 3 )
13891397
1398+ # rfc2696_cookie sometimes contains binary data from Microsoft Active Directory
1399+ # this breaks when calling to_ber. (Can't force binary data to UTF-8)
1400+ # we have to disable paging (even though server supports it) to get around this...
1401+
13901402 controls = [ ]
13911403 controls <<
13921404 [
0 commit comments