Added a new filter type bineq that will create an equality filter and NOT force

convert data to UTF-8. This is required for proper binary data filters in Microsoft
Active Directory.
This commit is contained in:
David J. Lee 2012-02-24 09:55:17 -06:00 committed by David Lee
parent 3345c58dfb
commit c46c93777e
4 changed files with 37 additions and 1 deletions

View file

@ -23,7 +23,7 @@
class Net::LDAP::Filter
##
# Known filter types.
FilterTypes = [ :ne, :eq, :ge, :le, :and, :or, :not, :ex ]
FilterTypes = [ :ne, :eq, :ge, :le, :and, :or, :not, :ex, :bineq ]
def initialize(op, left, right) #:nodoc:
unless FilterTypes.include?(op)
@ -65,6 +65,23 @@ class Net::LDAP::Filter
new(:eq, attribute, value)
end
##
# Creates a Filter object indicating a binary comparison.
# this prevents the search data from being forced into a UTF-8 string.
#
# This is primarily used for Microsoft Active Directory to compare
# GUID values.
#
# # for guid represented as hex charecters
# guid = "6a31b4a12aa27a41aca9603f27dd5116"
# guid_bin = [guid].pack("H*")
# f = Net::LDAP::Filter.bineq("objectGUID", guid_bin)
#
# This filter does not perform any escaping.
def bineq(attribute, value)
new(:bineq, attribute, value)
end
##
# Creates a Filter object indicating extensible comparison. This Filter
# object is currently considered EXPERIMENTAL.
@ -399,6 +416,8 @@ class Net::LDAP::Filter
"!(#{@left}=#{@right})"
when :eq
"#{@left}=#{@right}"
when :bineq
"#{@left}=#{@right}"
when :ex
"#{@left}:=#{@right}"
when :ge
@ -508,6 +527,9 @@ class Net::LDAP::Filter
else # equality
[@left.to_s.to_ber, unescape(@right).to_ber].to_ber_contextspecific(3)
end
when :bineq
# make sure data is not forced to UTF-8
[@left.to_s.to_ber, unescape(@right).to_ber_bin].to_ber_contextspecific(3)
when :ex
seq = []