Skip to content

Commit 5ff0350

Browse files
author
Jerry Cheung
committed
Merge remote-tracking branch 'nolman/master' into fix-whitespace
Conflicts: spec/integration/ssl_ber_spec.rb spec/unit/ber/ber_spec.rb spec/unit/ber/core_ext/string_spec.rb spec/unit/ldap/dn_spec.rb spec/unit/ldap/entry_spec.rb spec/unit/ldap/filter_spec.rb test/test_entry.rb
2 parents db29964 + f4c1b94 commit 5ff0350

File tree

8 files changed

+275
-288
lines changed

8 files changed

+275
-288
lines changed

lib/net/ber/core_ext.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,35 +28,35 @@ class String
2828

2929
require 'net/ber/core_ext/array'
3030
# :stopdoc:
31-
class Array
31+
class Array
3232
include Net::BER::Extensions::Array
3333
end
3434
# :startdoc:
3535

3636
require 'net/ber/core_ext/bignum'
3737
# :stopdoc:
38-
class Bignum
38+
class Bignum
3939
include Net::BER::Extensions::Bignum
4040
end
4141
# :startdoc:
4242

4343
require 'net/ber/core_ext/fixnum'
4444
# :stopdoc:
45-
class Fixnum
45+
class Fixnum
4646
include Net::BER::Extensions::Fixnum
4747
end
4848
# :startdoc:
4949

5050
require 'net/ber/core_ext/true_class'
5151
# :stopdoc:
52-
class TrueClass
52+
class TrueClass
5353
include Net::BER::Extensions::TrueClass
5454
end
5555
# :startdoc:
5656

5757
require 'net/ber/core_ext/false_class'
5858
# :stopdoc:
59-
class FalseClass
59+
class FalseClass
6060
include Net::BER::Extensions::FalseClass
6161
end
6262
# :startdoc:

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: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ class LdapError < StandardError; end
317317
DefaultPort = 389
318318
DefaultAuth = { :method => :anonymous }
319319
DefaultTreebase = "dc=com"
320-
DefaultForceNoPage = false
320+
DefaultForceNoPage = false
321321

322322
StartTlsOid = "1.3.6.1.4.1.1466.20037"
323323

@@ -398,7 +398,7 @@ def initialize(args = {})
398398
@verbose = false # Make this configurable with a switch on the class.
399399
@auth = args[:auth] || DefaultAuth
400400
@base = args[:base] || DefaultTreebase
401-
@force_no_page = args[:force_no_page] || DefaultForceNoPage
401+
@force_no_page = args[:force_no_page] || DefaultForceNoPage
402402
encryption args[:encryption] # may be nil
403403

404404
if pr = @auth[:password] and pr.respond_to?(:call)
@@ -486,7 +486,7 @@ def authenticate(username, password)
486486
# standard port for simple-TLS encrypted connections is 636. Be sure you
487487
# are using the correct port.
488488
#
489-
# The :start_tls like the :simple_tls encryption method also encrypts all
489+
# The :start_tls like the :simple_tls encryption method also encrypts all
490490
# communcations with the LDAP server. With the exception that it operates
491491
# over the standard TCP port.
492492
def encryption(args)
@@ -1168,10 +1168,10 @@ def search_subschema_entry
11681168
# MUST refactor the root_dse call out.
11691169
#++
11701170
def paged_searches_supported?
1171-
# active directory returns that it supports paged results. However
1172-
# it returns binary data in the rfc2696_cookie which throws an
1173-
# encoding exception breaking searching.
1174-
return false if @force_no_page
1171+
# active directory returns that it supports paged results. However
1172+
# it returns binary data in the rfc2696_cookie which throws an
1173+
# encoding exception breaking searching.
1174+
return false if @force_no_page
11751175
@server_caps ||= search_root_dse
11761176
@server_caps[:supportedcontrol].include?(Net::LDAP::LDAPControls::PAGED_RESULTS)
11771177
end

lib/net/ldap/entry.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def [](name)
115115

116116
##
117117
# Read the first value for the provided attribute. The attribute name
118-
# is canonicalized prior to reading. Returns nil if the attribute does
118+
# is canonicalized prior to reading. Returns nil if the attribute does
119119
# not exist.
120120
def first(name)
121121
self[name].first

lib/net/ldap/filter.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ def present?(attribute)
242242

243243
# http://tools.ietf.org/html/rfc4515 lists these exceptions from UTF1
244244
# charset for filters. All of the following must be escaped in any normal
245-
# string using a single backslash ('\') as escape.
245+
# string using a single backslash ('\') as escape.
246246
#
247247
ESCAPES = {
248248
"\0" => '00', # NUL = %x00 ; null character
@@ -251,10 +251,10 @@ def present?(attribute)
251251
')' => '29', # RPARENS = %x29 ; right parenthesis (")")
252252
'\\' => '5C', # ESC = %x5C ; esc (or backslash) ("\")
253253
}
254-
# Compiled character class regexp using the keys from the above hash.
254+
# Compiled character class regexp using the keys from the above hash.
255255
ESCAPE_RE = Regexp.new(
256-
"[" +
257-
ESCAPES.keys.map { |e| Regexp.escape(e) }.join +
256+
"[" +
257+
ESCAPES.keys.map { |e| Regexp.escape(e) }.join +
258258
"]")
259259

260260
##
@@ -310,8 +310,8 @@ def parse_ber(ber)
310310
present?(ber.to_s)
311311
when 0xa9 # context-specific constructed 9, "extensible comparison"
312312
raise Net::LDAP::LdapError, "Invalid extensible search filter, should be at least two elements" if ber.size<2
313-
314-
# Reassembles the extensible filter parts
313+
314+
# Reassembles the extensible filter parts
315315
# (["sn", "2.4.6.8.10", "Barbara Jones", '1'])
316316
type = value = dn = rule = nil
317317
ber.each do |element|
@@ -327,7 +327,7 @@ def parse_ber(ber)
327327
attribute << type if type
328328
attribute << ":#{dn}" if dn
329329
attribute << ":#{rule}" if rule
330-
330+
331331
ex(attribute, value)
332332
else
333333
raise Net::LDAP::LdapError, "Invalid BER tag-value (#{ber.ber_identifier}) in search filter."

lib/net/ldap/password.rb

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,17 @@ class << self
2121
#
2222
attribute_value = ""
2323
def generate(type, str)
24-
case type
25-
when :md5
26-
attribute_value = '{MD5}' + Base64.encode64(Digest::MD5.digest(str)).chomp!
27-
when :sha
28-
attribute_value = '{SHA}' + Base64.encode64(Digest::SHA1.digest(str)).chomp!
29-
when :ssha
30-
salt = SecureRandom.random_bytes(16)
31-
attribute_value = '{SSHA}' + Base64.encode64(Digest::SHA1.digest(str + salt) + salt).chomp!
32-
else
33-
raise Net::LDAP::LdapError, "Unsupported password-hash type (#{type})"
34-
end
24+
case type
25+
when :md5
26+
attribute_value = '{MD5}' + Base64.encode64(Digest::MD5.digest(str)).chomp!
27+
when :sha
28+
attribute_value = '{SHA}' + Base64.encode64(Digest::SHA1.digest(str)).chomp!
29+
when :ssha
30+
salt = SecureRandom.random_bytes(16)
31+
attribute_value = '{SSHA}' + Base64.encode64(Digest::SHA1.digest(str + salt) + salt).chomp!
32+
else
33+
raise Net::LDAP::LdapError, "Unsupported password-hash type (#{type})"
34+
end
3535
return attribute_value
3636
end
3737
end

0 commit comments

Comments
 (0)