Skip to content

Commit 60957bd

Browse files
committed
Synchronize with 0.50
1 parent 89d48ba commit 60957bd

File tree

15 files changed

+148
-35
lines changed

15 files changed

+148
-35
lines changed

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
source :rubygems
1+
source 'https://rubygems.org'
22
gemspec

History.rdoc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
=== Net::LDAP 0.5.0 / 2013-07-22
2+
* Major changes:
3+
* Required Ruby version is >=1.9.3
4+
* Major enhancements:
5+
* Added alias dereferencing (@ngwilson)
6+
* BER now unescapes characters that are already escaped in the source string (@jzinn)
7+
* BerIdentifiedString will now fall back to ASCII-8 encoding if the source Ruby object cannot be encoded in UTF-8 (@lfu)
8+
* Bug fixes:
9+
* Fixed nil variable error when following a reference response (@cmdrclueless)
10+
* Fixed FilterParser unable to parse multibyte strings (@satoryu)
11+
* Return ConverterNotFound when dealing with a potentially corrupt data response (@jamuc)
12+
113
=== Net::LDAP 0.4.0.cv / 2013-01-31
214
* Merge our (CloudVolumes) changes with upstream 4.0 changes
315

Manifest.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ lib/net/ldap/entry.rb
2525
lib/net/ldap/filter.rb
2626
lib/net/ldap/password.rb
2727
lib/net/ldap/pdu.rb
28+
lib/net/ldap/version.rb
2829
lib/net/snmp.rb
2930
net-ldap.gemspec
3031
spec/integration/ssl_ber_spec.rb

README.rdoc

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
= Net::LDAP for Ruby
1+
= Net::LDAP for Ruby {<img src="https://travis-ci.org/ruby-ldap/ruby-net-ldap.png" />}[https://travis-ci.org/ruby-ldap/ruby-net-ldap]
22

33
== Description
44

@@ -30,7 +30,7 @@ See Net::LDAP for documentation and usage samples.
3030

3131
== Requirements
3232

33-
Net::LDAP requires a Ruby 1.8.7 interpreter or better.
33+
Net::LDAP requires a Ruby 1.9.3 compatible interpreter or better.
3434

3535
== Install
3636

@@ -42,11 +42,6 @@ sources.
4242

4343
Simply require either 'net-ldap' or 'net/ldap'.
4444

45-
For non-RubyGems installations of Net::LDAP, you can use Minero Aoki's
46-
{setup.rb}[http://i.loveruby.net/en/projects/setup/] as the layout of
47-
Net::LDAP is compliant. The setup installer is not included in the
48-
Net::LDAP repository.
49-
5045
:include: Contributors.rdoc
5146

5247
:include: License.rdoc

lib/net/ber.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
# -*- ruby encoding: utf-8 -*-
2+
require 'net/ldap/version'
3+
24
module Net # :nodoc:
35
##
46
# == Basic Encoding Rules (BER) Support Module
@@ -106,7 +108,7 @@ module Net # :nodoc:
106108
# <tr><th>BMPString</th><th>C</th><td>30: 62 (0x3e, 0b00111110)</td></tr>
107109
# </table>
108110
module BER
109-
VERSION = '0.4.0.cv'
111+
VERSION = Net::LDAP::VERSION
110112

111113
##
112114
# Used for BER-encoding the length and content bytes of a Fixnum integer
@@ -296,7 +298,7 @@ class Net::BER::BerIdentifiedString < String
296298
def initialize args
297299
super args
298300
# LDAP uses UTF-8 encoded strings
299-
force_encoding('UTF-8') if respond_to?(:encoding)
301+
self.encode('UTF-8') if self.respond_to?(:encoding) rescue self
300302
end
301303
end
302304

lib/net/ber/core_ext/string.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ def raw_utf8_encoded
3232
self.encode('UTF-8').force_encoding('ASCII-8BIT')
3333
rescue Encoding::UndefinedConversionError
3434
self
35+
rescue Encoding::ConverterNotFoundError
36+
return self
3537
end
3638
else
3739
self

lib/net/ldap.rb

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class LDAP
2323
require 'net/ldap/dataset'
2424
require 'net/ldap/password'
2525
require 'net/ldap/entry'
26+
require 'net/ldap/version'
2627

2728
# == Quick-start for the Impatient
2829
# === Quick Example of a user-authentication against an LDAP directory:
@@ -241,8 +242,6 @@ class LDAP
241242
# and then keeps it open while it executes a user-supplied block.
242243
# Net::LDAP#open closes the connection on completion of the block.
243244
class Net::LDAP
244-
VERSION = "0.4.0.cv"
245-
246245
class LdapError < StandardError; end
247246

248247
SearchScope_BaseObject = 0
@@ -251,6 +250,12 @@ class LdapError < StandardError; end
251250
SearchScopes = [ SearchScope_BaseObject, SearchScope_SingleLevel,
252251
SearchScope_WholeSubtree ]
253252

253+
DerefAliases_Never = 0
254+
DerefAliases_Search = 1
255+
DerefAliases_Find = 2
256+
DerefAliases_Always = 3
257+
DerefAliasesArray = [ DerefAliases_Never, DerefAliases_Search, DerefAliases_Find, DerefAliases_Always ]
258+
254259
primitive = { 2 => :null } # UnbindRequest body
255260
constructed = {
256261
0 => :array, # BindRequest
@@ -594,6 +599,8 @@ def open
594599
# Net::LDAP::SearchScope_WholeSubtree. Default is WholeSubtree.)
595600
# * :size (an integer indicating the maximum number of search entries to
596601
# return. Default is zero, which signifies no limit.)
602+
# * :deref (one of: Net::LDAP::DerefAliases_Never, Net::LDAP::DerefAliases_Search,
603+
# Net::LDAP::DerefAliases_Find, Net::LDAP::DerefAliases_Always. Default is Never.)
597604
#
598605
# #search queries the LDAP server and passes <i>each entry</i> to the
599606
# caller-supplied block, as an object of type Net::LDAP::Entry. If the
@@ -1413,6 +1420,11 @@ def search(args = {})
14131420
raise Net::LDAP::LdapError, "invalid search scope" unless Net::LDAP::SearchScopes.include?(scope)
14141421

14151422
sort_control = encode_sort_controls(args.fetch(:sort_controls){ false })
1423+
1424+
deref = args[:deref] || Net::LDAP::DerefAliases_Never
1425+
raise Net::LDAP::LdapError.new( "invalid alias dereferencing value" ) unless Net::LDAP::DerefAliasesArray.include?(deref)
1426+
1427+
14161428
# An interesting value for the size limit would be close to A/D's
14171429
# built-in page limit of 1000 records, but openLDAP newer than version
14181430
# 2.2.0 chokes on anything bigger than 126. You get a silent error that
@@ -1452,7 +1464,7 @@ def search(args = {})
14521464
request = [
14531465
search_base.to_ber,
14541466
scope.to_ber_enumerated,
1455-
0.to_ber_enumerated,
1467+
deref.to_ber_enumerated,
14561468
query_limit.to_ber, # size limit
14571469
0.to_ber,
14581470
attributes_only.to_ber,
@@ -1497,7 +1509,7 @@ def search(args = {})
14971509
when 5 # search-result
14981510
result_pdu = pdu
14991511
controls = pdu.result_controls
1500-
if return_referrals && result_code == 10
1512+
if return_referrals && pdu.result_code == 10
15011513
if block_given?
15021514
se = Net::LDAP::Entry.new
15031515
se[:search_referrals] = (pdu.search_referrals || [])

lib/net/ldap/filter.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -291,11 +291,11 @@ def parse_ber(ber)
291291
case b.ber_identifier
292292
when 0x80 # context-specific primitive 0, SubstringFilter "initial"
293293
raise Net::LDAP::LdapError, "Unrecognized substring filter; bad initial value." if str.length > 0
294-
str += b
294+
str += escape(b)
295295
when 0x81 # context-specific primitive 0, SubstringFilter "any"
296-
str += "*#{b}"
296+
str += "*#{escape(b)}"
297297
when 0x82 # context-specific primitive 0, SubstringFilter "final"
298-
str += "*#{b}"
298+
str += "*#{escape(b)}"
299299
final = true
300300
end
301301
}
@@ -509,17 +509,17 @@ def to_ber
509509
first = nil
510510
ary.shift
511511
else
512-
first = ary.shift.to_ber_contextspecific(0)
512+
first = unescape(ary.shift).to_ber_contextspecific(0)
513513
end
514514

515515
if ary.last.empty?
516516
last = nil
517517
ary.pop
518518
else
519-
last = ary.pop.to_ber_contextspecific(2)
519+
last = unescape(ary.pop).to_ber_contextspecific(2)
520520
end
521521

522-
seq = ary.map { |e| e.to_ber_contextspecific(1) }
522+
seq = ary.map { |e| unescape(e).to_ber_contextspecific(1) }
523523
seq.unshift first if first
524524
seq.push last if last
525525

@@ -755,7 +755,7 @@ def parse_filter_branch(scanner)
755755
scanner.scan(/\s*/)
756756
if op = scanner.scan(/<=|>=|!=|:=|=/)
757757
scanner.scan(/\s*/)
758-
if value = scanner.scan(/(?:[-\w*.+@=,#\$%&!'\s\xC3\x80-\xCA\xAF]|\\[a-fA-F\d]{2})+/)
758+
if value = scanner.scan(/(?:[-\w*.+@=,#\$%&!'\s\xC3\x80-\xCA\xAF]|[^\x00-\x7F]|\\[a-fA-F\d]{2})+/u)
759759
# 20100313 AZ: Assumes that "(uid=george*)" is the same as
760760
# "(uid=george* )". The standard doesn't specify, but I can find
761761
# no examples that suggest otherwise.

lib/net/ldap/filter_parser_spec.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# encoding: utf-8
2+
require 'spec_helper'
3+
4+
describe Net::LDAP::Filter::FilterParser do
5+
6+
describe "#parse" do
7+
context "Given ASCIIs as filter string" do
8+
let(:filter_string) { "(cn=name)" }
9+
specify "should generate filter object" do
10+
expect(Net::LDAP::Filter::FilterParser.parse(filter_string)).to be_a Net::LDAP::Filter
11+
end
12+
end
13+
context "Given string including multibyte chars as filter string" do
14+
let(:filter_string) { "(cn=名前)" }
15+
specify "should generate filter object" do
16+
expect(Net::LDAP::Filter::FilterParser.parse(filter_string)).to be_a Net::LDAP::Filter
17+
end
18+
end
19+
end
20+
end

lib/net/ldap/version.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module Net
2+
class LDAP
3+
VERSION = "0.5.0.cv"
4+
end
5+
end

0 commit comments

Comments
 (0)