Import fixes from kschiess

This commit is contained in:
Rory OConnell 2010-02-10 12:13:59 -06:00
parent d37c3b3ae6
commit 4c24cf239a
6 changed files with 249 additions and 248 deletions

View file

@ -7,12 +7,18 @@ require 'hoe'
$LOAD_PATH.unshift( "#{File.dirname(__FILE__)}/lib" ) $LOAD_PATH.unshift( "#{File.dirname(__FILE__)}/lib" )
# Pull in local 'net/ldap' as opposed to an installed version. # Pull in local 'net/ldap' as opposed to an installed version.
require 'net/ldap' require 'net'
Hoe.new('net-ldap', Net::LDAP::VERSION) do |p| Hoe.spec "net-ldap" do
p.rubyforge_name = 'net-ldap' developer 'Francis Cianfrocca', 'garbagecat10@gmail.com'
p.developer('Francis Cianfrocca', 'garbagecat10@gmail.com') developer 'Emiel van de Laar', 'gemiel@gmail.com'
p.developer('Emiel van de Laar', 'gemiel@gmail.com') developer "Rory O'Connell", 'rory.ocon@gmail.com'
end end
# Hoe.new('net-ldap', Net::LDAP::VERSION) do |p|
# p.rubyforge_name = 'net-ldap'
# p.developer('Francis Cianfrocca', 'garbagecat10@gmail.com')
# p.developer('Emiel van de Laar', 'gemiel@gmail.com')
# end
# vim: syntax=Ruby # vim: syntax=Ruby

View file

@ -75,7 +75,6 @@ module Net
# This exceptionally clever and clear bit of code is verrrry slow. # This exceptionally clever and clear bit of code is verrrry slow.
objtype = (syntax && syntax[id]) || BuiltinSyntax[id] objtype = (syntax && syntax[id]) || BuiltinSyntax[id]
# == is expensive so sort this if/else so the common cases are at the top. # == is expensive so sort this if/else so the common cases are at the top.
obj = if objtype == :string obj = if objtype == :string
#(newobj || "").dup #(newobj || "").dup
@ -125,14 +124,12 @@ module Net
#raise BerError.new( "unsupported object type: class=#{tagclass}, encoding=#{encoding}, tag=#{tag}" ) #raise BerError.new( "unsupported object type: class=#{tagclass}, encoding=#{encoding}, tag=#{tag}" )
raise BerError.new( "unsupported object type: id=#{id}" ) raise BerError.new( "unsupported object type: id=#{id}" )
end end
# Add the identifier bits into the object if it's a String or an Array. # Add the identifier bits into the object if it's a String or an Array.
# We can't add extra stuff to Fixnums and booleans, not that it makes much sense anyway. # We can't add extra stuff to Fixnums and booleans, not that it makes much sense anyway.
# Replaced this mechanism with subclasses because the instance_eval profiled too hot. # Replaced this mechanism with subclasses because the instance_eval profiled too hot.
#obj and ([String,Array].include? obj.class) and obj.instance_eval "def ber_identifier; #{id}; end" #obj and ([String,Array].include? obj.class) and obj.instance_eval "def ber_identifier; #{id}; end"
#obj.ber_identifier = id if obj.respond_to?(:ber_identifier) #obj.ber_identifier = id if obj.respond_to?(:ber_identifier)
obj obj
end end
#-- #--
@ -146,8 +143,8 @@ module Net
# Observe that weirdly we recursively call the original #read_ber in here. # Observe that weirdly we recursively call the original #read_ber in here.
# That needs to be fixed if we ever obsolete the original method in favor of this one. # That needs to be fixed if we ever obsolete the original method in favor of this one.
def read_ber_from_string str, syntax=nil def read_ber_from_string str, syntax=nil
id = str[0] or return nil id = str[0].ord or return nil
n = str[1] or return nil n = str[1].ord or return nil
n_consumed = 2 n_consumed = 2
lengthlength,contentlength = if n <= 127 lengthlength,contentlength = if n <= 127
[1,n] [1,n]

View file

@ -30,24 +30,31 @@
module Net module Net
class LDAP class LDAP
class Dataset < Hash class Dataset < Hash
attr_reader :comments attr_reader :comments
class IOFilter
def initialize(io)
@io = io
end
def gets
s = @io.gets
s.chomp if s
end
end
def Dataset::read_ldif io def self.read_ldif io
ds = Dataset.new ds = Dataset.new
line = io.gets && chomp line = io.gets
dn = nil dn = nil
while line while line
io.gets and chomp io.gets and chomp
if $_ =~ /^[\s]+/ if new_line =~ /^[\s]+/
line << " " << $' line << " " << $'
else else
nextline = $_ nextline = new_line
if line =~ /^\#/ if line =~ /^\#/
ds.comments << line ds.comments << line
@ -81,28 +88,19 @@ class Dataset < Hash
def to_ldif def to_ldif
ary = [] ary = []
ary += (@comments || []) ary += (@comments || [])
keys.sort.each do |dn|
keys.sort.each {|dn|
ary << "dn: #{dn}" ary << "dn: #{dn}"
self[dn].keys.map {|sym| sym.to_s}.sort.each {|attr| self[dn].keys.map {|sym| sym.to_s}.sort.each do |attr|
self[dn][attr.intern].each {|val| self[dn][attr.intern].each {|val| ary << "#{attr}: #{val}" }
ary << "#{attr}: #{val}" end
}
}
ary << "" ary << ""
} end
block_given? and ary.each {|line| yield line} block_given? and ary.each {|line| yield line}
ary ary
end end
end
end # Dataset end
end
end # LDAP
end # Net

View file

@ -28,8 +28,6 @@
module Net module Net
class LDAP class LDAP
class Password class Password
class << self class << self
@ -41,22 +39,24 @@ class Password
# Should we provide sha1 as a synonym for sha1? I vote no because then # Should we provide sha1 as a synonym for sha1? I vote no because then
# should you also provide ssha1 for symmetry? # should you also provide ssha1 for symmetry?
def generate( type, str ) def generate( type, str )
case type digest, digest_name = case type
when :md5 when :md5
"{MD5}#{ [MD5.new( str.to_s ).digest].pack("m").chomp }" [Digest::MD5.new, 'MD5']
when :sha when :sha
"{SHA}#{ [SHA1.new( str.to_s ).digest].pack("m").chomp }" [Digest::SHA1.new, 'sha']
# when ssha # when ssha
else else
raise Net::LDAP::LdapError.new( "unsupported password-hash type (#{type})" ) raise Net::LDAP::LdapError.new( "unsupported password-hash type (#{type})" )
end end
digest << str.to_s
return "{#{digest_name}}#{[digest.digest].pack('m').chomp }"
end end
end
end
end end
end end
end # class LDAP
end # module Net

View file

@ -11,7 +11,7 @@ class TestLdif < Test::Unit::TestCase
TestLdifFilename = "#{File.dirname(__FILE__)}/testdata.ldif" TestLdifFilename = "#{File.dirname(__FILE__)}/testdata.ldif"
def test_empty_ldif def test_empty_ldif
ds = Net::LDAP::Dataset::read_ldif( StringIO.new ) ds = Net::LDAP::Dataset.read_ldif( StringIO.new )
assert_equal( true, ds.empty? ) assert_equal( true, ds.empty? )
end end

View file

@ -32,7 +32,7 @@ class TestSnmp < Test::Unit::TestCase
# partially-received data streams, such as from network connections. # partially-received data streams, such as from network connections.
def test_consume_string def test_consume_string
data = "xxx" data = "xxx"
assert_equal( nil, data.read_ber! ) assert_equal( data.read_ber!, nil )
assert_equal( "xxx", data ) assert_equal( "xxx", data )
data = SnmpGetRequest + "!!!" data = SnmpGetRequest + "!!!"