Skip to content

Commit 91db1ba

Browse files
committed
Define Sasl AuthAdapter
1 parent ac729dd commit 91db1ba

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

lib/net/ldap/auth_adapters/sasl.rb

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
require 'net/ldap/auth_adapter'
2+
3+
module Net
4+
class LDAP
5+
module AuthAdapters
6+
class Sasl < Net::LDAP::AuthAdapter
7+
def bind(auth)
8+
mech, cred, chall = auth[:mechanism], auth[:initial_credential],
9+
auth[:challenge_response]
10+
raise Net::LDAP::BindingInformationInvalidError, "Invalid binding information" unless (mech && cred && chall)
11+
12+
message_id = @connection.next_msgid
13+
14+
n = 0
15+
loop {
16+
sasl = [mech.to_ber, cred.to_ber].to_ber_contextspecific(3)
17+
request = [
18+
Net::LDAP::Connection::LdapVersion.to_ber, "".to_ber, sasl
19+
].to_ber_appsequence(Net::LDAP::PDU::BindRequest)
20+
21+
@connection.send(:write, request, nil, message_id)
22+
pdu = @connection.queued_read(message_id)
23+
24+
if !pdu || pdu.app_tag != Net::LDAP::PDU::BindResult
25+
raise Net::LDAP::NoBindResultError, "no bind result"
26+
end
27+
28+
return pdu unless pdu.result_code == Net::LDAP::ResultCodeSaslBindInProgress
29+
raise Net::LDAP::SASLChallengeOverflowError, "sasl-challenge overflow" if ((n += 1) > MaxSaslChallenges)
30+
31+
cred = chall.call(pdu.result_server_sasl_creds)
32+
}
33+
34+
raise Net::LDAP::SASLChallengeOverflowError, "why are we here?"
35+
end
36+
end
37+
end
38+
end
39+
end
40+
41+
Net::LDAP::AuthAdapter.register(:sasl, Net::LDAP::AuthAdapters::Sasl)

0 commit comments

Comments
 (0)