@@ -1182,14 +1182,22 @@ def delete(args)
11821182  # entries. This method sends an extra control code to tell the LDAP server 
11831183  # to do a tree delete. ('1.2.840.113556.1.4.805') 
11841184  # 
1185+   # If the LDAP server does not support the DELETE_TREE control code, subordinate 
1186+   # entries are deleted recursively instead. 
1187+   # 
11851188  # Returns True or False to indicate whether the delete succeeded. Extended 
11861189  # status information is available by calling #get_operation_result. 
11871190  # 
11881191  #  dn = "[email protected] , ou=people, dc=example, dc=com"  11891192  #  ldap.delete_tree :dn => dn 
11901193  def  delete_tree ( args ) 
1191-     delete ( args . merge ( :control_codes  =>  [ [ Net ::LDAP ::LDAPControls ::DELETE_TREE ,  true ] ] ) ) 
1194+     if  search_root_dse [ :supportedcontrol ] . include?  Net ::LDAP ::LDAPControls ::DELETE_TREE 
1195+       delete ( args . merge ( :control_codes  =>  [ [ Net ::LDAP ::LDAPControls ::DELETE_TREE ,  true ] ] ) ) 
1196+     else 
1197+       recursive_delete ( args ) 
1198+     end 
11921199  end 
1200+ 
11931201  # This method is experimental and subject to change. Return the rootDSE 
11941202  # record from the LDAP server as a Net::LDAP::Entry, or an empty Entry if 
11951203  # the server doesn't return the record. 
@@ -1340,4 +1348,19 @@ def normalize_encryption(args)
13401348    end 
13411349  end 
13421350
1351+   # Recursively delete a dn and it's subordinate children. 
1352+   # This is useful when a server does not support the DELETE_TREE control code. 
1353+   def  recursive_delete ( args ) 
1354+     raise  EmptyDNError  unless  args . is_a? ( Hash )  && args . has_key? ( :dn ) 
1355+     # Delete Children 
1356+     search ( base : args [ :dn ] ,  scope : Net ::LDAP ::SearchScope_SingleLevel )  do  |entry |
1357+       recursive_delete ( dn : entry . dn ) 
1358+     end 
1359+     # Delete Self 
1360+     unless  delete ( dn : args [ :dn ] ) 
1361+       raise  Net ::LDAP ::Error ,  self . get_operation_result [ :error_message ] . to_s 
1362+     end 
1363+     true 
1364+   end 
1365+ 
13431366end  # class LDAP 
0 commit comments