@@ -1022,6 +1022,19 @@ def delete(args)
10221022 @result == 0
10231023 end
10241024
1025+ # Delete an entry from the LDAP directory along with all subordinate entries.
1026+ # the regular delete method will fail to delete an entry if it has subordinate
1027+ # entries. This method sends an extra control code to tell the LDAP server
1028+ # to do a tree delete. ('1.2.840.113556.1.4.805')
1029+ #
1030+ # Returns True or False to indicate whether the delete succeeded. Extended
1031+ # status information is available by calling #get_operation_result.
1032+ #
1033+ # dn = "mail=deleteme@example.com, ou=people, dc=example, dc=com"
1034+ # ldap.delete_tree :dn => dn
1035+ def delete_tree ( args )
1036+ delete ( args . merge ( :control_codes => [ [ '1.2.840.113556.1.4.805' , true ] ] ) )
1037+ end
10251038 # This method is experimental and subject to change. Return the rootDSE
10261039 # record from the LDAP server as a Net::LDAP::Entry, or an empty Entry if
10271040 # the server doesn't return the record.
@@ -1545,9 +1558,9 @@ def rename args
15451558 #++
15461559 def delete ( args )
15471560 dn = args [ :dn ] or raise "Unable to delete empty DN"
1548-
1561+ controls = args . include? ( :control_codes ) ? args [ :control_codes ] . to_ber_control : nil #use nil so we can compact later
15491562 request = dn . to_s . to_ber_application_string ( 10 )
1550- pkt = [ next_msgid . to_ber , request ] . to_ber_sequence
1563+ pkt = [ next_msgid . to_ber , request , controls ] . compact . to_ber_sequence
15511564 @conn . write pkt
15521565
15531566 ( be = @conn . read_ber ( Net ::LDAP ::AsnSyntax ) ) && ( pdu = Net ::LDAP ::PDU . new ( be ) ) && ( pdu . app_tag == 11 ) or raise Net ::LDAP ::LdapError , "response missing or invalid"
0 commit comments