diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index c1d8b87a..9a54583e 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -293,7 +293,8 @@ Metrics/BlockNesting: # Offense count: 11 # Configuration parameters: CountComments, CountAsOne. Metrics/ClassLength: - Max: 443 + Max: 451 + # Offense count: 20 # Configuration parameters: AllowedMethods, AllowedPatterns. diff --git a/lib/net/ldap.rb b/lib/net/ldap.rb index 1547597f..d9c63914 100644 --- a/lib/net/ldap.rb +++ b/lib/net/ldap.rb @@ -341,6 +341,7 @@ class Net::LDAP StartTlsOid = '1.3.6.1.4.1.1466.20037' PasswdModifyOid = '1.3.6.1.4.1.4203.1.11.1' + WhoamiOid = '1.3.6.1.4.1.4203.1.11.3' # https://tools.ietf.org/html/rfc4511#section-4.1.9 # https://tools.ietf.org/html/rfc4511#appendix-A @@ -1198,6 +1199,23 @@ def delete_tree(args) end end + # Return the authorization identity of the client that issues the + # ldapwhoami request. The method does not support any arguments. + # + # Returns True or False to indicate whether the request was successfull. + # The result is available in the extended status information when calling + # #get_operation_result. + # + # ldap.ldapwhoami + # puts ldap.get_operation_result.extended_response + def ldapwhoami(args = {}) + instrument "ldapwhoami.net_ldap", args do |payload| + @result = use_connection(args, &:ldapwhoami) + @result.success? + end + end + alias_method :whoami, :ldapwhoami + # This method is experimental and subject to change. Return the rootDSE # record from the LDAP server as a Net::LDAP::Entry, or an empty Entry if # the server doesn't return the record. diff --git a/lib/net/ldap/connection.rb b/lib/net/ldap/connection.rb index be0db04b..6dac3e50 100644 --- a/lib/net/ldap/connection.rb +++ b/lib/net/ldap/connection.rb @@ -688,6 +688,24 @@ def delete(args) pdu end + def ldapwhoami + Net::LDAP::AsnSyntax[139] = :string + ext_seq = [Net::LDAP::WhoamiOid.to_ber_contextspecific(0)] + request = ext_seq.to_ber_appsequence(Net::LDAP::PDU::ExtendedRequest) + + message_id = next_msgid + + write(request, nil, message_id) + pdu = queued_read(message_id) + + if !pdu || pdu.app_tag != Net::LDAP::PDU::ExtendedResponse + raise Net::LDAP::ResponseMissingOrInvalidError, "response missing or invalid" + end + + Net::LDAP::AsnSyntax[139] = nil + pdu + end + # Internal: Returns a Socket like object used internally to communicate with # LDAP server. #