Class: LDAP::Server::Request
- Inherits:
-
Object
- Object
- LDAP::Server::Request
- Defined in:
- lib/ldap/server/request.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
Returns the value of attribute attributes.
-
#connection ⇒ Object
Returns the value of attribute connection.
-
#rescount ⇒ Object
Returns the value of attribute rescount.
-
#sizelimit ⇒ Object
Returns the value of attribute sizelimit.
-
#typesOnly ⇒ Object
Returns the value of attribute typesOnly.
Instance Method Summary collapse
-
#initialize(connection, messageId) ⇒ Request
constructor
Object to handle a single LDAP request.
- #send_AddResponse(resultCode, opt = {}) ⇒ Object
- #send_BindResponse(resultCode, opt = {}) ⇒ Object
- #send_CompareResponse(resultCode, opt = {}) ⇒ Object
- #send_DelResponse(resultCode, opt = {}) ⇒ Object
- #send_ExtendedResponse(resultCode, opt = {}) ⇒ Object
-
#send_LDAPMessage(protocolOp, opt = {}) ⇒ Object
Utility methods to send protocol responses ###.
-
#send_LDAPResult(tag, resultCode, opt = {}) {|seq| ... } ⇒ Object
:nodoc:.
- #send_ModifyDNResponse(resultCode, opt = {}) ⇒ Object
- #send_ModifyResponse(resultCode, opt = {}) ⇒ Object
- #send_SearchResultDone(resultCode, opt = {}) ⇒ Object
-
#send_SearchResultEntry(dn, avs, opt = {}) ⇒ Object
Send a found entry.
-
#server_sizelimit ⇒ Object
Server-set maximum size limit.
-
#server_timelimit ⇒ Object
Server-set maximum time limit.
Constructor Details
#initialize(connection, messageId) ⇒ Request
Object to handle a single LDAP request. This object is created on every request by the router, and is passed as argument to the defined routes.
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/ldap/server/request.rb', line 13 def initialize(connection, ) @connection = connection @respEnvelope = OpenSSL::ASN1::Sequence([ OpenSSL::ASN1::Integer(), # protocolOp, # controls [0] OPTIONAL, ]) @schema = @connection.opt[:schema] @server = @connection.opt[:server] @rescount = 0 end |
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
7 8 9 |
# File 'lib/ldap/server/request.rb', line 7 def attributes @attributes end |
#connection ⇒ Object
Returns the value of attribute connection.
7 8 9 |
# File 'lib/ldap/server/request.rb', line 7 def connection @connection end |
#rescount ⇒ Object
Returns the value of attribute rescount.
7 8 9 |
# File 'lib/ldap/server/request.rb', line 7 def rescount @rescount end |
#sizelimit ⇒ Object
Returns the value of attribute sizelimit.
7 8 9 |
# File 'lib/ldap/server/request.rb', line 7 def sizelimit @sizelimit end |
#typesOnly ⇒ Object
Returns the value of attribute typesOnly.
7 8 9 |
# File 'lib/ldap/server/request.rb', line 7 def typesOnly @typesOnly end |
Instance Method Details
#send_AddResponse(resultCode, opt = {}) ⇒ Object
118 119 120 |
# File 'lib/ldap/server/request.rb', line 118 def send_AddResponse(resultCode, opt={}) send_LDAPResult(9, resultCode, opt) end |
#send_BindResponse(resultCode, opt = {}) ⇒ Object
55 56 57 58 59 60 61 |
# File 'lib/ldap/server/request.rb', line 55 def send_BindResponse(resultCode, opt={}) send_LDAPResult(1, resultCode, opt) do |resp| if opt[:serverSaslCreds] resp << OpenSSL::ASN1::OctetString(opt[:serverSaslCreds], 7, :IMPLICIT, :APPLICATION) end end end |
#send_CompareResponse(resultCode, opt = {}) ⇒ Object
130 131 132 |
# File 'lib/ldap/server/request.rb', line 130 def send_CompareResponse(resultCode, opt={}) send_LDAPResult(15, resultCode, opt) end |
#send_DelResponse(resultCode, opt = {}) ⇒ Object
122 123 124 |
# File 'lib/ldap/server/request.rb', line 122 def send_DelResponse(resultCode, opt={}) send_LDAPResult(11, resultCode, opt) end |
#send_ExtendedResponse(resultCode, opt = {}) ⇒ Object
134 135 136 137 138 139 140 141 142 143 |
# File 'lib/ldap/server/request.rb', line 134 def send_ExtendedResponse(resultCode, opt={}) send_LDAPResult(24, resultCode, opt) do |resp| if opt[:responseName] resp << OpenSSL::ASN1::OctetString(opt[:responseName], 10, :IMPLICIT, :APPLICATION) end if opt[:response] resp << OpenSSL::ASN1::OctetString(opt[:response], 11, :IMPLICIT, :APPLICATION) end end end |
#send_LDAPMessage(protocolOp, opt = {}) ⇒ Object
Utility methods to send protocol responses ###
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/ldap/server/request.rb', line 29 def send_LDAPMessage(protocolOp, opt={}) # :nodoc: @respEnvelope.value[1] = protocolOp if opt[:controls] @respEnvelope.value[2] = OpenSSL::ASN1::Set(opt[:controls], 0, :IMPLICIT, APPLICATION) else @respEnvelope.value.delete_at(2) end @connection.write(@respEnvelope.to_der) end |
#send_LDAPResult(tag, resultCode, opt = {}) {|seq| ... } ⇒ Object
:nodoc:
40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/ldap/server/request.rb', line 40 def send_LDAPResult(tag, resultCode, opt={}) # :nodoc: seq = [ OpenSSL::ASN1::Enumerated(resultCode), OpenSSL::ASN1::OctetString(opt[:matchedDN] || ""), OpenSSL::ASN1::OctetString(opt[:errorMessage] || ""), ] if opt[:referral] rs = opt[:referral].collect { |r| OpenSSL::ASN1::OctetString(r) } seq << OpenSSL::ASN1::Sequence(rs, 3, :IMPLICIT, :APPLICATION) end yield seq if block_given? # opportunity to add more elements send_LDAPMessage(OpenSSL::ASN1::Sequence(seq, tag, :IMPLICIT, :APPLICATION), opt) end |
#send_ModifyDNResponse(resultCode, opt = {}) ⇒ Object
126 127 128 |
# File 'lib/ldap/server/request.rb', line 126 def send_ModifyDNResponse(resultCode, opt={}) send_LDAPResult(13, resultCode, opt) end |
#send_ModifyResponse(resultCode, opt = {}) ⇒ Object
114 115 116 |
# File 'lib/ldap/server/request.rb', line 114 def send_ModifyResponse(resultCode, opt={}) send_LDAPResult(7, resultCode, opt) end |
#send_SearchResultDone(resultCode, opt = {}) ⇒ Object
110 111 112 |
# File 'lib/ldap/server/request.rb', line 110 def send_SearchResultDone(resultCode, opt={}) send_LDAPResult(5, resultCode, opt) end |
#send_SearchResultEntry(dn, avs, opt = {}) ⇒ Object
Send a found entry. Avs are attr2=> If schema given, return operational attributes only if explicitly requested
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/ldap/server/request.rb', line 67 def send_SearchResultEntry(dn, avs, opt={}) @rescount += 1 if @sizelimit raise LDAP::ResultError::SizeLimitExceeded if @rescount > @sizelimit end if @schema # normalize the attribute names @attributes = @attributes.map { |a| a == '*' ? a : @schema.find_attrtype(a).to_s } end sendall = @attributes == [] || @attributes.include?("*") avseq = [] avs.each do |attr, vals| if !@attributes.include?(attr) next unless sendall if @schema a = @schema.find_attrtype(attr) next unless a and (a.usage.nil? or a.usage == :userApplications) end end if @typesOnly vals = [] else vals = [vals] unless vals.kind_of?(Array) # FIXME: optionally do a value_to_s conversion here? # FIXME: handle attribute;binary end avseq << OpenSSL::ASN1::Sequence([ OpenSSL::ASN1::OctetString(attr), OpenSSL::ASN1::Set(vals.collect { |v| OpenSSL::ASN1::OctetString(v.to_s) }) ]) end send_LDAPMessage(OpenSSL::ASN1::Sequence([ OpenSSL::ASN1::OctetString(dn), OpenSSL::ASN1::Sequence(avseq), ], 4, :IMPLICIT, :APPLICATION), opt) end |
#server_sizelimit ⇒ Object
Server-set maximum size limit. Override for more complex behaviour (e.g. limit depends on @connection.binddn). Return nil for unlimited.
159 160 161 |
# File 'lib/ldap/server/request.rb', line 159 def server_sizelimit @connection.opt[:sizelimit] end |
#server_timelimit ⇒ Object
Server-set maximum time limit. Override for more complex behaviour (e.g. limit depends on @connection.binddn). Nil uses hardcoded default.
152 153 154 |
# File 'lib/ldap/server/request.rb', line 152 def server_timelimit @connection.opt[:timelimit] end |