Import fixes from kschiess
This commit is contained in:
parent
d37c3b3ae6
commit
4c24cf239a
16
Rakefile
16
Rakefile
|
@ -7,12 +7,18 @@ require 'hoe'
|
|||
$LOAD_PATH.unshift( "#{File.dirname(__FILE__)}/lib" )
|
||||
|
||||
# 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|
|
||||
p.rubyforge_name = 'net-ldap'
|
||||
p.developer('Francis Cianfrocca', 'garbagecat10@gmail.com')
|
||||
p.developer('Emiel van de Laar', 'gemiel@gmail.com')
|
||||
Hoe.spec "net-ldap" do
|
||||
developer 'Francis Cianfrocca', 'garbagecat10@gmail.com'
|
||||
developer 'Emiel van de Laar', 'gemiel@gmail.com'
|
||||
developer "Rory O'Connell", 'rory.ocon@gmail.com'
|
||||
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
|
||||
|
|
|
@ -75,7 +75,6 @@ module Net
|
|||
# This exceptionally clever and clear bit of code is verrrry slow.
|
||||
objtype = (syntax && syntax[id]) || BuiltinSyntax[id]
|
||||
|
||||
|
||||
# == is expensive so sort this if/else so the common cases are at the top.
|
||||
obj = if objtype == :string
|
||||
#(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: id=#{id}" )
|
||||
end
|
||||
|
||||
# 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.
|
||||
# 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.ber_identifier = id if obj.respond_to?(:ber_identifier)
|
||||
obj
|
||||
|
||||
end
|
||||
|
||||
#--
|
||||
|
@ -146,8 +143,8 @@ module Net
|
|||
# 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.
|
||||
def read_ber_from_string str, syntax=nil
|
||||
id = str[0] or return nil
|
||||
n = str[1] or return nil
|
||||
id = str[0].ord or return nil
|
||||
n = str[1].ord or return nil
|
||||
n_consumed = 2
|
||||
lengthlength,contentlength = if n <= 127
|
||||
[1,n]
|
||||
|
|
|
@ -30,24 +30,31 @@
|
|||
|
||||
module Net
|
||||
class LDAP
|
||||
|
||||
class Dataset < Hash
|
||||
|
||||
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
|
||||
|
||||
line = io.gets && chomp
|
||||
line = io.gets
|
||||
dn = nil
|
||||
|
||||
while line
|
||||
io.gets and chomp
|
||||
if $_ =~ /^[\s]+/
|
||||
if new_line =~ /^[\s]+/
|
||||
line << " " << $'
|
||||
else
|
||||
nextline = $_
|
||||
nextline = new_line
|
||||
|
||||
if line =~ /^\#/
|
||||
ds.comments << line
|
||||
|
@ -81,28 +88,19 @@ class Dataset < Hash
|
|||
def to_ldif
|
||||
ary = []
|
||||
ary += (@comments || [])
|
||||
|
||||
keys.sort.each {|dn|
|
||||
keys.sort.each do |dn|
|
||||
ary << "dn: #{dn}"
|
||||
|
||||
self[dn].keys.map {|sym| sym.to_s}.sort.each {|attr|
|
||||
self[dn][attr.intern].each {|val|
|
||||
ary << "#{attr}: #{val}"
|
||||
}
|
||||
}
|
||||
self[dn].keys.map {|sym| sym.to_s}.sort.each do |attr|
|
||||
self[dn][attr.intern].each {|val| ary << "#{attr}: #{val}" }
|
||||
end
|
||||
|
||||
ary << ""
|
||||
}
|
||||
|
||||
end
|
||||
block_given? and ary.each {|line| yield line}
|
||||
|
||||
ary
|
||||
end
|
||||
|
||||
|
||||
end # Dataset
|
||||
|
||||
end # LDAP
|
||||
end # Net
|
||||
|
||||
|
||||
end
|
||||
end
|
||||
end
|
|
@ -28,8 +28,6 @@
|
|||
|
||||
module Net
|
||||
class LDAP
|
||||
|
||||
|
||||
class Password
|
||||
class << self
|
||||
|
||||
|
@ -41,22 +39,24 @@ class Password
|
|||
# Should we provide sha1 as a synonym for sha1? I vote no because then
|
||||
# should you also provide ssha1 for symmetry?
|
||||
def generate( type, str )
|
||||
case type
|
||||
digest, digest_name = case type
|
||||
when :md5
|
||||
"{MD5}#{ [MD5.new( str.to_s ).digest].pack("m").chomp }"
|
||||
[Digest::MD5.new, 'MD5']
|
||||
when :sha
|
||||
"{SHA}#{ [SHA1.new( str.to_s ).digest].pack("m").chomp }"
|
||||
[Digest::SHA1.new, 'sha']
|
||||
# when ssha
|
||||
else
|
||||
raise Net::LDAP::LdapError.new( "unsupported password-hash type (#{type})" )
|
||||
end
|
||||
|
||||
digest << str.to_s
|
||||
return "{#{digest_name}}#{[digest.digest].pack('m').chomp }"
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
end # class LDAP
|
||||
end # module Net
|
||||
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ class TestLdif < Test::Unit::TestCase
|
|||
TestLdifFilename = "#{File.dirname(__FILE__)}/testdata.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? )
|
||||
end
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@ class TestSnmp < Test::Unit::TestCase
|
|||
# partially-received data streams, such as from network connections.
|
||||
def test_consume_string
|
||||
data = "xxx"
|
||||
assert_equal( nil, data.read_ber! )
|
||||
assert_equal( data.read_ber!, nil )
|
||||
assert_equal( "xxx", data )
|
||||
|
||||
data = SnmpGetRequest + "!!!"
|
||||
|
|
Loading…
Reference in a new issue