Module: ROM::LDAP::Client::Operations Private

Included in:
ROM::LDAP::Client
Defined in:
lib/rom/ldap/client/operations.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Adds entry creation capability to the connection.

Instance Method Summary collapse

Instance Method Details

#add(dn:, attrs:) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters:

  • :dn (Hash)

    a customizable set of options

  • :attrs (Hash)

    a customizable set of options



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/rom/ldap/client/operations.rb', line 100

def add(dn:, attrs:)
  request_type = pdu_lookup(:add_request)

  ber_attrs = attrs.each_with_object([]) do |(k, v), attributes|
    ber_values = values_to_ber_set(v)
    attributes << [k.to_s.to_ber, ber_values].to_ber_sequence
  end

  request = [
    dn.to_ber,
    ber_attrs.to_ber_sequence
  ].to_ber_appsequence(request_type)

  submit(:add_response, request)
end

#delete(dn:, controls: nil) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters:

  • :dn (Hash)

    a customizable set of options

  • :controls (Hash)

    a customizable set of options



121
122
123
124
125
126
127
128
129
130
# File 'lib/rom/ldap/client/operations.rb', line 121

def delete(dn:, controls: nil)
  request_type = pdu_lookup(:delete_request)
  request = dn.to_ber_application_string(request_type)

  if controls
    submit(:delete_response, request, controls.to_ber_control)
  else
    submit(:delete_response, request)
  end
end

#password_modify(dn:, old_pwd: nil, new_pwd:) ⇒ PDU

Password should have a minimum of 5 characters.

Parameters:

  • :dn (Hash)

    a customizable set of options

  • :old_pwd (Hash)

    a customizable set of options

  • :new_pwd (Hash)

    a customizable set of options

Returns:

  • (PDU)

    result object

See Also:



189
190
191
192
193
194
195
196
197
198
199
200
201
# File 'lib/rom/ldap/client/operations.rb', line 189

def password_modify(dn:, old_pwd: nil, new_pwd:)
  request_type = pdu_lookup(:extended_request)
  context = OID[:password_modify].to_ber_contextspecific(0)

  payload = [dn.to_ber(0x80)]
  payload << old_pwd.to_ber(0x81) if old_pwd
  payload << new_pwd.to_ber(0x82)
  payload = payload.to_ber_sequence.to_ber(0x81)

  request = [context, payload].to_ber_appsequence(request_type)

  submit(:extended_response, request)
end

#rename(dn:, rdn:, replace: false, superior: nil) ⇒ PDU

TODO: spec rename and use by relations

Parameters:

  • :dn (Hash)

    a customizable set of options

  • :rdn (Hash)

    a customizable set of options

  • :replace (Hash)

    a customizable set of options

  • :superior (Hash)

    a customizable set of options

Returns:

  • (PDU)

    result object



164
165
166
167
168
169
170
171
172
173
174
# File 'lib/rom/ldap/client/operations.rb', line 164

def rename(dn:, rdn:, replace: false, superior: nil)
  request_type = pdu_lookup(:modify_rdn_request)

  request = [dn, rdn, replace].map { |a| a.to_ber } # &:to_ber

  request << superior.to_ber_contextspecific(0) if superior

  request = request.to_ber_appsequence(request_type)

  submit(:modify_rdn_response, request)
end

#search(return_refs: true, **params) {|Entry| ... } ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

TODO:

Write spec for yielding search_referrals

Connection Search Operation

Yields:

  • (Entry)
  • (Hash)

    :search_referrals

See Also:



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
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
# File 'lib/rom/ldap/client/operations.rb', line 27

def search(return_refs: true, **params)
  search_request = SearchRequest.new(params)
  request_type   = pdu_lookup(:search_request)
  result_pdu     = nil

  more_pages = false
  paged_results_cookie = [126, EMPTY_STRING]
  # paged_results_cookie = [10, EMPTY_STRING]

  request    = search_request.parts.to_ber_appsequence(request_type)
  controls   = search_request.controls
  message_id = next_msgid

  loop do
    write(request, message_id, controls)

    result_pdu = nil
    controls   = EMPTY_ARRAY

    while (pdu = from_queue(message_id))
      case pdu.app_tag
      when pdu_lookup(:search_returned_data) # 4
        yield(pdu.search_entry)

      when pdu_lookup(:search_result) # 5
        result_pdu = pdu
        controls   = pdu.result_controls
        yield(search_referrals: pdu.search_referrals) if return_refs && pdu.search_referral?
        break

      when pdu_lookup(:search_result_referral) # 19
        yield(search_referrals: pdu.search_referrals) if return_refs

      else
        raise ResponseTypeInvalidError, "invalid response-type in search: #{pdu.app_tag}"
      end
    end

    if result_pdu&.success?
      controls.each do |c|
        next if c.oid != OID[:paged_results]

        next if c.value&.empty?

        # [ 0, "" ]
        _int, cookie = c.value.read_ber

        # next page of results
        #
        unless cookie&.empty?

          # cookie => "\u0001\u0000\u0000"
          # cookie.read_ber => true

          paged_results_cookie[1] = cookie
          more_pages = true
        end
      end
    end

    break unless more_pages
  end

  result_pdu
ensure
  queue.delete(message_id)
end

#update(dn:, ops:) ⇒ PDU

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns result object.

Parameters:

  • :dn (Hash)

    a customizable set of options

  • :ops (Hash)

    a customizable set of options

Returns:

  • (PDU)

    result object



139
140
141
142
143
144
145
146
147
148
149
# File 'lib/rom/ldap/client/operations.rb', line 139

def update(dn:, ops:)
  request_type = pdu_lookup(:modify_request)
  operations = modify_ops(ops)

  request = [
    dn.to_ber,
    operations.to_ber_sequence
  ].to_ber_appsequence(request_type)

  submit(:modify_response, request)
end