@@ -256,6 +256,7 @@ class LdapError < Exception; end
256256 14 => :array , # CompareRequest
257257 15 => :array , # CompareResponse
258258 16 => :array , # AbandonRequest
259+ 24 => :array , # Unsolicited Notification
259260 }
260261 } ,
261262 :context_specific => {
@@ -275,6 +276,7 @@ class LdapError < Exception; end
275276 ResultStrings = {
276277 0 => "Success" ,
277278 1 => "Operations Error" ,
279+ 2 => "Protocol Error" ,
278280 16 => "No Such Attribute" ,
279281 17 => "Undefined Attribute Type" ,
280282 20 => "Attribute or Value Exists" ,
@@ -629,6 +631,31 @@ def modify_rdn args
629631 rename args
630632 end
631633
634+ # Delete an entry from the LDAP directory.
635+ # Takes a hash of arguments.
636+ # The only supported argument is :dn, which must
637+ # give the complete DN of the entry to be deleted.
638+ # Returns True or False to indicate whether the delete
639+ # succeeded. Extended status information is available by
640+ # calling #get_operation_result.
641+ #
642+ # dn = "mail=deleteme@example.com,ou=people,dc=example,dc=com"
643+ # ldap.delete :dn => dn
644+ #
645+ def delete args
646+ if @open_connection
647+ @result = @open_connection . delete ( args )
648+ else
649+ @result = 0
650+ conn = Connection . new ( :host => @host , :port => @port )
651+ if ( @result = conn . bind ( args [ :auth ] || @auth ) ) == 0
652+ @result = conn . delete ( args )
653+ end
654+ conn . close
655+ end
656+ @result == 0
657+ end
658+
632659 end # class LDAP
633660
634661
@@ -854,6 +881,22 @@ def rename args
854881 end
855882
856883
884+ #--
885+ # delete
886+ # TODO, need to support a time limit, in case the server fails to respond.
887+ #
888+ def delete args
889+ dn = args [ :dn ] or raise "Unable to delete empty DN"
890+
891+ request = dn . to_s . to_ber_application_string ( 10 )
892+ pkt = [ next_msgid . to_ber , request ] . to_ber_sequence
893+ @conn . write pkt
894+
895+ ( be = @conn . read_ber ( AsnSyntax ) ) && ( pdu = LdapPdu . new ( be ) ) && ( pdu . app_tag == 11 ) or raise LdapError . new ( "response missing or invalid" )
896+ pdu . result_code
897+ end
898+
899+
857900 end # class Connection
858901 end # class LDAP
859902
0 commit comments