Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/AnonR/anonr.TX.../opt/alt/ruby27/share/ruby/uri
File: ldap.rb
# frozen_string_literal: false
[0] Fix | Delete
# = uri/ldap.rb
[1] Fix | Delete
#
[2] Fix | Delete
# Author::
[3] Fix | Delete
# Takaaki Tateishi <ttate@jaist.ac.jp>
[4] Fix | Delete
# Akira Yamada <akira@ruby-lang.org>
[5] Fix | Delete
# License::
[6] Fix | Delete
# URI::LDAP is copyrighted free software by Takaaki Tateishi and Akira Yamada.
[7] Fix | Delete
# You can redistribute it and/or modify it under the same term as Ruby.
[8] Fix | Delete
# Revision:: $Id$
[9] Fix | Delete
#
[10] Fix | Delete
# See URI for general documentation
[11] Fix | Delete
#
[12] Fix | Delete
[13] Fix | Delete
require_relative 'generic'
[14] Fix | Delete
[15] Fix | Delete
module URI
[16] Fix | Delete
[17] Fix | Delete
#
[18] Fix | Delete
# LDAP URI SCHEMA (described in RFC2255).
[19] Fix | Delete
#--
[20] Fix | Delete
# ldap://<host>/<dn>[?<attrs>[?<scope>[?<filter>[?<extensions>]]]]
[21] Fix | Delete
#++
[22] Fix | Delete
class LDAP < Generic
[23] Fix | Delete
[24] Fix | Delete
# A Default port of 389 for URI::LDAP.
[25] Fix | Delete
DEFAULT_PORT = 389
[26] Fix | Delete
[27] Fix | Delete
# An Array of the available components for URI::LDAP.
[28] Fix | Delete
COMPONENT = [
[29] Fix | Delete
:scheme,
[30] Fix | Delete
:host, :port,
[31] Fix | Delete
:dn,
[32] Fix | Delete
:attributes,
[33] Fix | Delete
:scope,
[34] Fix | Delete
:filter,
[35] Fix | Delete
:extensions,
[36] Fix | Delete
].freeze
[37] Fix | Delete
[38] Fix | Delete
# Scopes available for the starting point.
[39] Fix | Delete
#
[40] Fix | Delete
# * SCOPE_BASE - the Base DN
[41] Fix | Delete
# * SCOPE_ONE - one level under the Base DN, not including the base DN and
[42] Fix | Delete
# not including any entries under this
[43] Fix | Delete
# * SCOPE_SUB - subtrees, all entries at all levels
[44] Fix | Delete
#
[45] Fix | Delete
SCOPE = [
[46] Fix | Delete
SCOPE_ONE = 'one',
[47] Fix | Delete
SCOPE_SUB = 'sub',
[48] Fix | Delete
SCOPE_BASE = 'base',
[49] Fix | Delete
].freeze
[50] Fix | Delete
[51] Fix | Delete
#
[52] Fix | Delete
# == Description
[53] Fix | Delete
#
[54] Fix | Delete
# Creates a new URI::LDAP object from components, with syntax checking.
[55] Fix | Delete
#
[56] Fix | Delete
# The components accepted are host, port, dn, attributes,
[57] Fix | Delete
# scope, filter, and extensions.
[58] Fix | Delete
#
[59] Fix | Delete
# The components should be provided either as an Array, or as a Hash
[60] Fix | Delete
# with keys formed by preceding the component names with a colon.
[61] Fix | Delete
#
[62] Fix | Delete
# If an Array is used, the components must be passed in the
[63] Fix | Delete
# order <code>[host, port, dn, attributes, scope, filter, extensions]</code>.
[64] Fix | Delete
#
[65] Fix | Delete
# Example:
[66] Fix | Delete
#
[67] Fix | Delete
# uri = URI::LDAP.build({:host => 'ldap.example.com',
[68] Fix | Delete
# :dn => '/dc=example'})
[69] Fix | Delete
#
[70] Fix | Delete
# uri = URI::LDAP.build(["ldap.example.com", nil,
[71] Fix | Delete
# "/dc=example;dc=com", "query", nil, nil, nil])
[72] Fix | Delete
#
[73] Fix | Delete
def self.build(args)
[74] Fix | Delete
tmp = Util::make_components_hash(self, args)
[75] Fix | Delete
[76] Fix | Delete
if tmp[:dn]
[77] Fix | Delete
tmp[:path] = tmp[:dn]
[78] Fix | Delete
end
[79] Fix | Delete
[80] Fix | Delete
query = []
[81] Fix | Delete
[:extensions, :filter, :scope, :attributes].collect do |x|
[82] Fix | Delete
next if !tmp[x] && query.size == 0
[83] Fix | Delete
query.unshift(tmp[x])
[84] Fix | Delete
end
[85] Fix | Delete
[86] Fix | Delete
tmp[:query] = query.join('?')
[87] Fix | Delete
[88] Fix | Delete
return super(tmp)
[89] Fix | Delete
end
[90] Fix | Delete
[91] Fix | Delete
#
[92] Fix | Delete
# == Description
[93] Fix | Delete
#
[94] Fix | Delete
# Creates a new URI::LDAP object from generic URI components as per
[95] Fix | Delete
# RFC 2396. No LDAP-specific syntax checking is performed.
[96] Fix | Delete
#
[97] Fix | Delete
# Arguments are +scheme+, +userinfo+, +host+, +port+, +registry+, +path+,
[98] Fix | Delete
# +opaque+, +query+, and +fragment+, in that order.
[99] Fix | Delete
#
[100] Fix | Delete
# Example:
[101] Fix | Delete
#
[102] Fix | Delete
# uri = URI::LDAP.new("ldap", nil, "ldap.example.com", nil, nil,
[103] Fix | Delete
# "/dc=example;dc=com", nil, "query", nil)
[104] Fix | Delete
#
[105] Fix | Delete
# See also URI::Generic.new.
[106] Fix | Delete
#
[107] Fix | Delete
def initialize(*arg)
[108] Fix | Delete
super(*arg)
[109] Fix | Delete
[110] Fix | Delete
if @fragment
[111] Fix | Delete
raise InvalidURIError, 'bad LDAP URL'
[112] Fix | Delete
end
[113] Fix | Delete
[114] Fix | Delete
parse_dn
[115] Fix | Delete
parse_query
[116] Fix | Delete
end
[117] Fix | Delete
[118] Fix | Delete
# Private method to cleanup +dn+ from using the +path+ component attribute.
[119] Fix | Delete
def parse_dn
[120] Fix | Delete
raise InvalidURIError, 'bad LDAP URL' unless @path
[121] Fix | Delete
@dn = @path[1..-1]
[122] Fix | Delete
end
[123] Fix | Delete
private :parse_dn
[124] Fix | Delete
[125] Fix | Delete
# Private method to cleanup +attributes+, +scope+, +filter+, and +extensions+
[126] Fix | Delete
# from using the +query+ component attribute.
[127] Fix | Delete
def parse_query
[128] Fix | Delete
@attributes = nil
[129] Fix | Delete
@scope = nil
[130] Fix | Delete
@filter = nil
[131] Fix | Delete
@extensions = nil
[132] Fix | Delete
[133] Fix | Delete
if @query
[134] Fix | Delete
attrs, scope, filter, extensions = @query.split('?')
[135] Fix | Delete
[136] Fix | Delete
@attributes = attrs if attrs && attrs.size > 0
[137] Fix | Delete
@scope = scope if scope && scope.size > 0
[138] Fix | Delete
@filter = filter if filter && filter.size > 0
[139] Fix | Delete
@extensions = extensions if extensions && extensions.size > 0
[140] Fix | Delete
end
[141] Fix | Delete
end
[142] Fix | Delete
private :parse_query
[143] Fix | Delete
[144] Fix | Delete
# Private method to assemble +query+ from +attributes+, +scope+, +filter+, and +extensions+.
[145] Fix | Delete
def build_path_query
[146] Fix | Delete
@path = '/' + @dn
[147] Fix | Delete
[148] Fix | Delete
query = []
[149] Fix | Delete
[@extensions, @filter, @scope, @attributes].each do |x|
[150] Fix | Delete
next if !x && query.size == 0
[151] Fix | Delete
query.unshift(x)
[152] Fix | Delete
end
[153] Fix | Delete
@query = query.join('?')
[154] Fix | Delete
end
[155] Fix | Delete
private :build_path_query
[156] Fix | Delete
[157] Fix | Delete
# Returns dn.
[158] Fix | Delete
def dn
[159] Fix | Delete
@dn
[160] Fix | Delete
end
[161] Fix | Delete
[162] Fix | Delete
# Private setter for dn +val+.
[163] Fix | Delete
def set_dn(val)
[164] Fix | Delete
@dn = val
[165] Fix | Delete
build_path_query
[166] Fix | Delete
@dn
[167] Fix | Delete
end
[168] Fix | Delete
protected :set_dn
[169] Fix | Delete
[170] Fix | Delete
# Setter for dn +val+.
[171] Fix | Delete
def dn=(val)
[172] Fix | Delete
set_dn(val)
[173] Fix | Delete
val
[174] Fix | Delete
end
[175] Fix | Delete
[176] Fix | Delete
# Returns attributes.
[177] Fix | Delete
def attributes
[178] Fix | Delete
@attributes
[179] Fix | Delete
end
[180] Fix | Delete
[181] Fix | Delete
# Private setter for attributes +val+.
[182] Fix | Delete
def set_attributes(val)
[183] Fix | Delete
@attributes = val
[184] Fix | Delete
build_path_query
[185] Fix | Delete
@attributes
[186] Fix | Delete
end
[187] Fix | Delete
protected :set_attributes
[188] Fix | Delete
[189] Fix | Delete
# Setter for attributes +val+.
[190] Fix | Delete
def attributes=(val)
[191] Fix | Delete
set_attributes(val)
[192] Fix | Delete
val
[193] Fix | Delete
end
[194] Fix | Delete
[195] Fix | Delete
# Returns scope.
[196] Fix | Delete
def scope
[197] Fix | Delete
@scope
[198] Fix | Delete
end
[199] Fix | Delete
[200] Fix | Delete
# Private setter for scope +val+.
[201] Fix | Delete
def set_scope(val)
[202] Fix | Delete
@scope = val
[203] Fix | Delete
build_path_query
[204] Fix | Delete
@scope
[205] Fix | Delete
end
[206] Fix | Delete
protected :set_scope
[207] Fix | Delete
[208] Fix | Delete
# Setter for scope +val+.
[209] Fix | Delete
def scope=(val)
[210] Fix | Delete
set_scope(val)
[211] Fix | Delete
val
[212] Fix | Delete
end
[213] Fix | Delete
[214] Fix | Delete
# Returns filter.
[215] Fix | Delete
def filter
[216] Fix | Delete
@filter
[217] Fix | Delete
end
[218] Fix | Delete
[219] Fix | Delete
# Private setter for filter +val+.
[220] Fix | Delete
def set_filter(val)
[221] Fix | Delete
@filter = val
[222] Fix | Delete
build_path_query
[223] Fix | Delete
@filter
[224] Fix | Delete
end
[225] Fix | Delete
protected :set_filter
[226] Fix | Delete
[227] Fix | Delete
# Setter for filter +val+.
[228] Fix | Delete
def filter=(val)
[229] Fix | Delete
set_filter(val)
[230] Fix | Delete
val
[231] Fix | Delete
end
[232] Fix | Delete
[233] Fix | Delete
# Returns extensions.
[234] Fix | Delete
def extensions
[235] Fix | Delete
@extensions
[236] Fix | Delete
end
[237] Fix | Delete
[238] Fix | Delete
# Private setter for extensions +val+.
[239] Fix | Delete
def set_extensions(val)
[240] Fix | Delete
@extensions = val
[241] Fix | Delete
build_path_query
[242] Fix | Delete
@extensions
[243] Fix | Delete
end
[244] Fix | Delete
protected :set_extensions
[245] Fix | Delete
[246] Fix | Delete
# Setter for extensions +val+.
[247] Fix | Delete
def extensions=(val)
[248] Fix | Delete
set_extensions(val)
[249] Fix | Delete
val
[250] Fix | Delete
end
[251] Fix | Delete
[252] Fix | Delete
# Checks if URI has a path.
[253] Fix | Delete
# For URI::LDAP this will return +false+.
[254] Fix | Delete
def hierarchical?
[255] Fix | Delete
false
[256] Fix | Delete
end
[257] Fix | Delete
end
[258] Fix | Delete
[259] Fix | Delete
@@schemes['LDAP'] = LDAP
[260] Fix | Delete
end
[261] Fix | Delete
[262] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function