Significant mods to LDAP#search
This commit is contained in:
parent
193f76e530
commit
7be5474f06
3 changed files with 178 additions and 17 deletions
71
lib/net/ldap/entry.rb
Normal file
71
lib/net/ldap/entry.rb
Normal file
|
@ -0,0 +1,71 @@
|
|||
# $Id$
|
||||
#
|
||||
# LDAP Entry (search-result) support classes
|
||||
#
|
||||
#
|
||||
#----------------------------------------------------------------------------
|
||||
#
|
||||
# Copyright (C) 2006 by Francis Cianfrocca. All Rights Reserved.
|
||||
#
|
||||
# Gmail: garbagecat10
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
#
|
||||
#---------------------------------------------------------------------------
|
||||
#
|
||||
|
||||
|
||||
|
||||
|
||||
module Net
|
||||
class LDAP
|
||||
|
||||
|
||||
class Entry
|
||||
|
||||
def initialize dn = nil
|
||||
@myhash = Hash.new {|k,v| k[v] = [] }
|
||||
self[:dn] = [dn]
|
||||
end
|
||||
|
||||
|
||||
def []= name, value
|
||||
sym = name.to_s.downcase.intern
|
||||
@myhash[sym] = value
|
||||
end
|
||||
|
||||
def [] name
|
||||
unless name.is_a?(Symbol)
|
||||
name = name.to_s.downcase.intern
|
||||
end
|
||||
@myhash[name]
|
||||
end
|
||||
|
||||
def dn
|
||||
self[:dn].shift
|
||||
end
|
||||
|
||||
def attribute_names
|
||||
@myhash.keys
|
||||
end
|
||||
|
||||
|
||||
end # class Entry
|
||||
|
||||
|
||||
end # class LDAP
|
||||
end # module Net
|
||||
|
||||
|
|
@ -44,7 +44,7 @@ class LdapPdu
|
|||
ModifyRDNResponse = 13
|
||||
|
||||
attr_reader :msg_id, :app_tag
|
||||
attr_reader :search_dn, :search_attributes
|
||||
attr_reader :search_dn, :search_attributes, :search_entry
|
||||
|
||||
#
|
||||
# initialize
|
||||
|
@ -129,12 +129,17 @@ class LdapPdu
|
|||
# NOW OBSERVE CAREFULLY: WE ARE DOWNCASING THE RETURNED ATTRIBUTE NAMES.
|
||||
# This is to make them more predictable for user programs, but it
|
||||
# may not be a good idea. Maybe this should be configurable.
|
||||
# ALTERNATE IMPLEMENTATION: In addition to @search_dn and @search_attributes,
|
||||
# we also return @search_entry, which is an LDAP::Entry object.
|
||||
# If that works out well, then we'll remove the first two.
|
||||
#
|
||||
def parse_search_return sequence
|
||||
sequence.length >= 2 or raise LdapPduError
|
||||
@search_entry = LDAP::Entry.new( sequence[0] )
|
||||
@search_dn = sequence[0]
|
||||
@search_attributes = {}
|
||||
sequence[1].each {|seq|
|
||||
@search_entry[seq[0]] = seq[1]
|
||||
@search_attributes[seq[0].downcase.intern] = seq[1]
|
||||
}
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue