@@ -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
@@ -373,6 +374,8 @@ def self.result2string(code) #:nodoc:
373374 # specifying the Hash {:method => :simple_tls}. There is a fairly large
374375 # range of potential values that may be given for this parameter. See
375376 # #encryption for details.
377+ # * :force_no_page => Set to true to prevent paged results even if your
378+ # server says it supports them. This is a fix for MS Active Directory
376379 #
377380 # Instantiating a Net::LDAP object does <i>not</i> result in network
378381 # traffic to the LDAP server. It simply stores the connection and binding
@@ -383,6 +386,7 @@ def initialize(args = {})
383386 @verbose = false # Make this configurable with a switch on the class.
384387 @auth = args [ :auth ] || DefaultAuth
385388 @base = args [ :base ] || DefaultTreebase
389+ @force_no_page = args [ :force_no_page ] || DefaultForceNoPage
386390 encryption args [ :encryption ] # may be nil
387391
388392 if pr = @auth [ :password ] and pr . respond_to? ( :call )
@@ -1108,6 +1112,10 @@ def search_subschema_entry
11081112 # MUST refactor the root_dse call out.
11091113 #++
11101114 def paged_searches_supported?
1115+ # active directory returns that it supports paged results. However
1116+ # it returns binary data in the rfc2696_cookie which throws an
1117+ # encoding exception breaking searching.
1118+ return false if @force_no_page
11111119 @server_caps ||= search_root_dse
11121120 @server_caps [ :supportedcontrol ] . include? ( Net ::LDAP ::LDAPControls ::PAGED_RESULTS )
11131121 end
@@ -1433,6 +1441,10 @@ def search(args = {})
14331441 search_attributes . to_ber_sequence
14341442 ] . to_ber_appsequence ( 3 )
14351443
1444+ # rfc2696_cookie sometimes contains binary data from Microsoft Active Directory
1445+ # this breaks when calling to_ber. (Can't force binary data to UTF-8)
1446+ # we have to disable paging (even though server supports it) to get around this...
1447+
14361448 controls = [ ]
14371449 controls <<
14381450 [
@@ -1582,7 +1594,7 @@ def add(args)
15821594 #--
15831595 # TODO: need to support a time limit, in case the server fails to respond.
15841596 #++
1585- def rename args
1597+ def rename ( args )
15861598 old_dn = args [ :olddn ] or raise "Unable to rename empty DN"
15871599 new_rdn = args [ :newrdn ] or raise "Unable to rename to empty RDN"
15881600 delete_attrs = args [ :delete_attributes ] ? true : false
0 commit comments