Skip to content

Commit 40b62bf

Browse files
author
steve
committed
Merge our forked changes with upstream 4.0 changes
1 parent 8a18267 commit 40b62bf

File tree

9 files changed

+72
-49
lines changed

9 files changed

+72
-49
lines changed

History.rdoc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
=== Net::LDAP 0.3.1.sv1 / 2012-05-15
2+
* Fixed unicode string encoding over LDAP.
3+
4+
=== Net::LDAP 0.3.1.sv0 / 2012-03-28
5+
* Minor Enhancements:
6+
* Added keepaive.
7+
18
=== Net::LDAP 0.3.1 / 2012-02-15
29
* Bug Fixes:
310
* Bundler should now work again

lib/net/ber.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ module Net # :nodoc:
106106
# <tr><th>BMPString</th><th>C</th><td>30: 62 (0x3e, 0b00111110)</td></tr>
107107
# </table>
108108
module BER
109-
VERSION = '0.4.0'
109+
VERSION = '0.3.1.sv1'
110110

111111
##
112112
# Used for BER-encoding the length and content bytes of a Fixnum integer

lib/net/ber/core_ext/string.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ def to_ber(code = 0x04)
1616
[code].pack('C') + raw_string.length.to_ber_length_encoding + raw_string
1717
end
1818

19-
##
20-
# Converts a string to a BER string but does *not* encode to UTF-8 first.
21-
# This is required for proper representation of binary data for Microsoft
22-
# Active Directory
23-
def to_ber_bin(code = 0x04)
24-
[code].pack('C') + length.to_ber_length_encoding + self
25-
end
19+
##
20+
# Converts a string to a BER string but does *not* encode to UTF-8 first.
21+
# This is required for proper representation of binary data for Microsoft
22+
# Active Directory
23+
def to_ber_bin(code = 0x04)
24+
[code].pack('C') + length.to_ber_length_encoding + self
25+
end
2626

2727
def raw_utf8_encoded
2828
if self.respond_to?(:encode)

lib/net/ldap.rb

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ class LDAP
241241
# and then keeps it open while it executes a user-supplied block.
242242
# Net::LDAP#open closes the connection on completion of the block.
243243
class Net::LDAP
244-
VERSION = "0.4.0"
244+
VERSION = "0.3.1.sv1"
245245

246246
class LdapError < StandardError; end
247247

@@ -308,7 +308,8 @@ class LdapError < StandardError; end
308308
DefaultPort = 389
309309
DefaultAuth = { :method => :anonymous }
310310
DefaultTreebase = "dc=com"
311-
DefaultForceNoPage = false
311+
DefaultForceNoPage = false
312+
DefaultKeepalive = true
312313

313314
StartTlsOid = "1.3.6.1.4.1.1466.20037"
314315

@@ -387,7 +388,8 @@ def initialize(args = {})
387388
@verbose = false # Make this configurable with a switch on the class.
388389
@auth = args[:auth] || DefaultAuth
389390
@base = args[:base] || DefaultTreebase
390-
@force_no_page = args[:force_no_page] || DefaultForceNoPage
391+
@force_no_page = args[:force_no_page] || DefaultForceNoPage
392+
@keepalive = args[:keepalive] || DefaultKeepalive
391393
encryption args[:encryption] # may be nil
392394

393395
if pr = @auth[:password] and pr.respond_to?(:call)
@@ -660,6 +662,15 @@ def search(args = {})
660662
end
661663
end
662664

665+
# #unbind explicitly disconnects from an LDAP server
666+
def unbind
667+
if @open_connection
668+
conn = @open_connection
669+
@open_connection = nil
670+
conn.close
671+
end
672+
end
673+
663674
# #bind connects to an LDAP server and requests authentication based on
664675
# the <tt>:auth</tt> parameter passed to #open or #new. It takes no
665676
# parameters.
@@ -725,6 +736,11 @@ def bind(auth = @auth)
725736
conn = Connection.new(:host => @host, :port => @port,
726737
:encryption => @encryption)
727738
@result = conn.bind(auth)
739+
if @keepalive
740+
@open_connection.close if @open_connection
741+
@open_connection = conn
742+
conn = nil
743+
end
728744
ensure
729745
conn.close if conn
730746
end
@@ -1115,10 +1131,10 @@ def search_subschema_entry
11151131
# MUST refactor the root_dse call out.
11161132
#++
11171133
def paged_searches_supported?
1118-
# active directory returns that it supports paged results. However
1119-
# it returns binary data in the rfc2696_cookie which throws an
1120-
# encoding exception breaking searching.
1121-
return false if @force_no_page
1134+
# active directory returns that it supports paged results. However
1135+
# it returns binary data in the rfc2696_cookie which throws an
1136+
# encoding exception breaking searching.
1137+
return false if @force_no_page
11221138
@server_caps ||= search_root_dse
11231139
@server_caps[:supportedcontrol].include?(Net::LDAP::LDAPControls::PAGED_RESULTS)
11241140
end
@@ -1444,9 +1460,9 @@ def search(args = {})
14441460
search_attributes.to_ber_sequence
14451461
].to_ber_appsequence(3)
14461462

1447-
# rfc2696_cookie sometimes contains binary data from Microsoft Active Directory
1448-
# this breaks when calling to_ber. (Can't force binary data to UTF-8)
1449-
# we have to disable paging (even though server supports it) to get around this...
1463+
# rfc2696_cookie sometimes contains binary data from Microsoft Active Directory
1464+
# this breaks when calling to_ber. (Can't force binary data to UTF-8)
1465+
# we have to disable paging (even though server supports it) to get around this...
14501466

14511467
controls = []
14521468
controls <<

lib/net/ldap/filter.rb

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -65,22 +65,22 @@ def eq(attribute, value)
6565
new(:eq, attribute, value)
6666
end
6767

68-
##
69-
# Creates a Filter object indicating a binary comparison.
70-
# this prevents the search data from being forced into a UTF-8 string.
71-
#
72-
# This is primarily used for Microsoft Active Directory to compare
73-
# GUID values.
74-
#
75-
# # for guid represented as hex charecters
76-
# guid = "6a31b4a12aa27a41aca9603f27dd5116"
77-
# guid_bin = [guid].pack("H*")
78-
# f = Net::LDAP::Filter.bineq("objectGUID", guid_bin)
79-
#
80-
# This filter does not perform any escaping.
81-
def bineq(attribute, value)
82-
new(:bineq, attribute, value)
83-
end
68+
##
69+
# Creates a Filter object indicating a binary comparison.
70+
# this prevents the search data from being forced into a UTF-8 string.
71+
#
72+
# This is primarily used for Microsoft Active Directory to compare
73+
# GUID values.
74+
#
75+
# # for guid represented as hex charecters
76+
# guid = "6a31b4a12aa27a41aca9603f27dd5116"
77+
# guid_bin = [guid].pack("H*")
78+
# f = Net::LDAP::Filter.bineq("objectGUID", guid_bin)
79+
#
80+
# This filter does not perform any escaping.
81+
def bineq(attribute, value)
82+
new(:bineq, attribute, value)
83+
end
8484

8585
##
8686
# Creates a Filter object indicating extensible comparison. This Filter
@@ -416,8 +416,8 @@ def to_raw_rfc2254
416416
"!(#{@left}=#{@right})"
417417
when :eq
418418
"#{@left}=#{@right}"
419-
when :bineq
420-
"#{@left}=#{@right}"
419+
when :bineq
420+
"#{@left}=#{@right}"
421421
when :ex
422422
"#{@left}:=#{@right}"
423423
when :ge
@@ -527,9 +527,9 @@ def to_ber
527527
else # equality
528528
[@left.to_s.to_ber, unescape(@right).to_ber].to_ber_contextspecific(3)
529529
end
530-
when :bineq
531-
# make sure data is not forced to UTF-8
532-
[@left.to_s.to_ber, unescape(@right).to_ber_bin].to_ber_contextspecific(3)
530+
when :bineq
531+
# make sure data is not forced to UTF-8
532+
[@left.to_s.to_ber, unescape(@right).to_ber_bin].to_ber_contextspecific(3)
533533
when :ex
534534
seq = []
535535

lib/net/ldap/password.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ class << self
2222
def generate(type, str)
2323
case type
2424
when :md5
25-
attribute_value = '{MD5}' + Base64.encode64(Digest::MD5.digest(str)).chomp!
25+
attribute_value = '{MD5}' + Base64.encode64(Digest::MD5.digest(str)).chomp!
2626
when :sha
27-
attribute_value = '{SHA}' + Base64.encode64(Digest::SHA1.digest(str)).chomp!
27+
attribute_value = '{SHA}' + Base64.encode64(Digest::SHA1.digest(str)).chomp!
2828
when :ssha
29-
srand; salt = (rand * 1000).to_i.to_s
29+
srand; salt = (rand * 1000).to_i.to_s
3030
attribute_value = '{SSHA}' + Base64.encode64(Digest::SHA1.digest(str + salt) + salt).chomp!
3131
else
3232
raise Net::LDAP::LdapError, "Unsupported password-hash type (#{type})"

lib/net/snmp.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# :stopdoc:
33
module Net
44
class SNMP
5-
VERSION = '0.4.0'
5+
VERSION = '0.3.1.sv1'
66

77
AsnSyntax = Net::BER.compile_syntax({
88
:application => {

net-ldap.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# -*- encoding: utf-8 -*-
22
Gem::Specification.new do |s|
33
s.name = %q{net-ldap}
4-
s.version = "0.4.0"
4+
s.version = "0.3.1.sv1"
55

66
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
77
s.authors = ["Francis Cianfrocca", "Emiel van de Laar", "Rory O'Connell", "Kaspar Schiess", "Austin Ziegler"]

spec/unit/ber/ber_spec.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,11 @@
8484
it "should properly encode strings encodable as UTF-8" do
8585
"teststring".encode("US-ASCII").to_ber.should == "\x04\nteststring"
8686
end
87-
it "should properly encode binary data strings using to_ber_bin" do
88-
# This is used for searching for GUIDs in Active Directory
89-
["6a31b4a12aa27a41aca9603f27dd5116"].pack("H*").to_ber_bin.should ==
90-
"\x04\x10" + "j1\xB4\xA1*\xA2zA\xAC\xA9`?'\xDDQ\x16"
91-
end
87+
it "should properly encode binary data strings using to_ber_bin" do
88+
# This is used for searching for GUIDs in Active Directory
89+
["6a31b4a12aa27a41aca9603f27dd5116"].pack("H*").to_ber_bin.should ==
90+
"\x04\x10" + "j1\xB4\xA1*\xA2zA\xAC\xA9`?'\xDDQ\x16"
91+
end
9292
it "should fail on strings that can not be converted to UTF-8" do
9393
error = Encoding::UndefinedConversionError
9494
lambda {"\x81".to_ber }.should raise_exception(error)

0 commit comments

Comments
 (0)