supported LDAP delete

This commit is contained in:
blackhedd 2006-04-30 16:31:08 +00:00
parent 5c18a30088
commit 5eaacf1ac3
3 changed files with 47 additions and 1 deletions

View file

@ -68,7 +68,7 @@ module Net
# this can throw TypeErrors and other nasties. # this can throw TypeErrors and other nasties.
# #
def read_ber syntax=nil def read_ber syntax=nil
eof? and return nil return nil if eof?
id = getc # don't trash this value, we'll use it later id = getc # don't trash this value, we'll use it later
tag = id & 31 tag = id & 31

View file

@ -256,6 +256,7 @@ module Net
14 => :array, # CompareRequest 14 => :array, # CompareRequest
15 => :array, # CompareResponse 15 => :array, # CompareResponse
16 => :array, # AbandonRequest 16 => :array, # AbandonRequest
24 => :array, # Unsolicited Notification
} }
}, },
:context_specific => { :context_specific => {
@ -275,6 +276,7 @@ module Net
ResultStrings = { ResultStrings = {
0 => "Success", 0 => "Success",
1 => "Operations Error", 1 => "Operations Error",
2 => "Protocol Error",
16 => "No Such Attribute", 16 => "No Such Attribute",
17 => "Undefined Attribute Type", 17 => "Undefined Attribute Type",
20 => "Attribute or Value Exists", 20 => "Attribute or Value Exists",
@ -629,6 +631,31 @@ module Net
rename args rename args
end end
# Delete an entry from the LDAP directory.
# Takes a hash of arguments.
# The only supported argument is :dn, which must
# give the complete DN of the entry to be deleted.
# Returns True or False to indicate whether the delete
# succeeded. Extended status information is available by
# calling #get_operation_result.
#
# dn = "mail=deleteme@example.com,ou=people,dc=example,dc=com"
# ldap.delete :dn => dn
#
def delete args
if @open_connection
@result = @open_connection.delete( args )
else
@result = 0
conn = Connection.new( :host => @host, :port => @port )
if (@result = conn.bind( args[:auth] || @auth )) == 0
@result = conn.delete( args )
end
conn.close
end
@result == 0
end
end # class LDAP end # class LDAP
@ -854,6 +881,22 @@ module Net
end end
#--
# delete
# TODO, need to support a time limit, in case the server fails to respond.
#
def delete args
dn = args[:dn] or raise "Unable to delete empty DN"
request = dn.to_s.to_ber_application_string(10)
pkt = [next_msgid.to_ber, request].to_ber_sequence
@conn.write pkt
(be = @conn.read_ber(AsnSyntax)) && (pdu = LdapPdu.new( be )) && (pdu.app_tag == 11) or raise LdapError.new( "response missing or invalid" )
pdu.result_code
end
end # class Connection end # class Connection
end # class LDAP end # class LDAP

View file

@ -41,6 +41,7 @@ class LdapPdu
SearchResult = 5 SearchResult = 5
ModifyResponse = 7 ModifyResponse = 7
AddResponse = 9 AddResponse = 9
DeleteResponse = 11
ModifyRDNResponse = 13 ModifyRDNResponse = 13
attr_reader :msg_id, :app_tag attr_reader :msg_id, :app_tag
@ -81,6 +82,8 @@ class LdapPdu
parse_ldap_result ber_object[1] parse_ldap_result ber_object[1]
when AddResponse when AddResponse
parse_ldap_result ber_object[1] parse_ldap_result ber_object[1]
when DeleteResponse
parse_ldap_result ber_object[1]
when ModifyRDNResponse when ModifyRDNResponse
parse_ldap_result ber_object[1] parse_ldap_result ber_object[1]
else else