Skip to content

Commit a7b8e5e

Browse files
a7b81a9086a7b81a9086
a7b81a9086
authored and
a7b81a9086
committed
Add support for ldapwhoami (RFC4532)
1 parent d6bb5c8 commit a7b8e5e

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

Diff for: lib/net/ldap.rb

+19
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,7 @@ class Net::LDAP
306306
3 => :string, # SearchFilter-extensible
307307
4 => :string, # SearchFilter-extensible
308308
7 => :string, # serverSaslCreds
309+
11 => :string, # responseValue
309310
}
310311
constructed = {
311312
0 => :array, # RFC-2251 Control and Filter-AND
@@ -341,6 +342,7 @@ class Net::LDAP
341342

342343
StartTlsOid = '1.3.6.1.4.1.1466.20037'
343344
PasswdModifyOid = '1.3.6.1.4.1.4203.1.11.1'
345+
WhoamiOid = '1.3.6.1.4.1.4203.1.11.3'
344346

345347
# https://tools.ietf.org/html/rfc4511#section-4.1.9
346348
# https://tools.ietf.org/html/rfc4511#appendix-A
@@ -1198,6 +1200,23 @@ def delete_tree(args)
11981200
end
11991201
end
12001202

1203+
# Return the authorization identity of the client that issues the
1204+
# ldapwhoami request. The method does not support any arguments.
1205+
#
1206+
# Returns True or False to indicate whether the request was successfull.
1207+
# The result is available in the extended status information when calling
1208+
# #get_operation_result.
1209+
#
1210+
# ldap.ldapwhoami
1211+
# puts ldap.get_operation_result.extended_response
1212+
def ldapwhoami(args = {})
1213+
instrument "ldapwhoami.net_ldap", args do |payload|
1214+
@result = use_connection(args, &:ldapwhoami)
1215+
@result.success?
1216+
end
1217+
end
1218+
alias_method :whoami, :ldapwhoami
1219+
12011220
# This method is experimental and subject to change. Return the rootDSE
12021221
# record from the LDAP server as a Net::LDAP::Entry, or an empty Entry if
12031222
# the server doesn't return the record.

Diff for: lib/net/ldap/connection.rb

+16
Original file line numberDiff line numberDiff line change
@@ -685,6 +685,22 @@ def delete(args)
685685
pdu
686686
end
687687

688+
def ldapwhoami
689+
ext_seq = [Net::LDAP::WhoamiOid.to_ber_contextspecific(0)]
690+
request = ext_seq.to_ber_appsequence(Net::LDAP::PDU::ExtendedRequest)
691+
692+
message_id = next_msgid
693+
694+
write(request, nil, message_id)
695+
pdu = queued_read(message_id)
696+
697+
if !pdu || pdu.app_tag != Net::LDAP::PDU::ExtendedResponse
698+
raise Net::LDAP::ResponseMissingOrInvalidError, "response missing or invalid"
699+
end
700+
701+
pdu
702+
end
703+
688704
# Internal: Returns a Socket like object used internally to communicate with
689705
# LDAP server.
690706
#

0 commit comments

Comments
 (0)