Skip to content

Commit 14c3db9

Browse files
author
blackhedd
committed
provisionally implemented NTLM authentication.
1 parent f3e87dd commit 14c3db9

File tree

2 files changed

+28
-6
lines changed

2 files changed

+28
-6
lines changed

lib/net/ldap.rb

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1159,21 +1159,37 @@ def bind auth
11591159

11601160
#--
11611161
# bind_sasl
1162-
# PROVISIONAL, only for testing SASL implementations. Will disappear, so DON'T USE THIS.
1162+
# PROVISIONAL, only for testing SASL implementations. DON'T USE THIS YET.
1163+
# Uses Kohei Kajimoto's Ruby/NTLM. We have to find a clean way to integrate it without
1164+
# introducing an external dependency.
1165+
# This is also wrong for another reason: we're assuming Microsoft GSSAPI negotiation.
1166+
# Wee need to introduce some extra parameters to select that mode.
11631167
def bind_sasl auth
1164-
user = auth[:username] or raise LdapError.new( "invalid username" )
1168+
require 'ntlm.rb'
1169+
user,psw = [auth[:username] || auth[:dn], auth[:password]]
1170+
raise LdapError.new( "invalid binding information" ) unless (user && psw)
1171+
msgid = next_msgid.to_ber
1172+
sasl = ["GSS-SPNEGO".to_ber, NTLM::Message::Type1.new.serialize.to_ber].to_ber_contextspecific(3)
1173+
request = [LdapVersion.to_ber, "".to_ber, sasl].to_ber_appsequence(0)
1174+
request_pkt = [msgid, request].to_ber_sequence
1175+
@conn.write request_pkt
1176+
1177+
(be = @conn.read_ber(AsnSyntax) and pdu = Net::LdapPdu.new( be )) or raise LdapError.new( "no bind result" )
1178+
return pdu.result_code unless pdu.result_code == 14 # saslBindInProgress
1179+
1180+
t2 = NTLM::Message.parse( pdu.result_server_sasl_creds ) # WARNING, can Kajimoto's code throw nasty errors?
1181+
t3 = t2.response( {:user => user, :password => psw}, {:ntlmv2 => true} )
1182+
11651183
msgid = next_msgid.to_ber
1166-
sasl = ["GSS-SPNEGO".to_ber, "NTLMSSP\000\001\000\000\000\227\202\010\340\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000".to_ber].to_ber_contextspecific(3)
1167-
sasl = ["GSSAPI".to_ber].to_ber_contextspecific(3)
1184+
sasl = ["GSS-SPNEGO".to_ber, t3.serialize.to_ber].to_ber_contextspecific(3)
11681185
request = [LdapVersion.to_ber, "".to_ber, sasl].to_ber_appsequence(0)
11691186
request_pkt = [msgid, request].to_ber_sequence
11701187
@conn.write request_pkt
1171-
p request_pkt
11721188

11731189
(be = @conn.read_ber(AsnSyntax) and pdu = Net::LdapPdu.new( be )) or raise LdapError.new( "no bind result" )
1174-
p pdu
11751190
pdu.result_code
11761191
end
1192+
private :bind_sasl
11771193

11781194
#--
11791195
# search

lib/net/ldap/pdu.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,12 @@ def result_controls
119119
@ldap_controls || []
120120
end
121121

122+
# Return serverSaslCreds, which are only present in BindResponse packets.
123+
# Messy. Does this functionality belong somewhere else?
124+
# We ought to refactor the accessors of this class before they get any kludgier.
125+
def result_server_sasl_creds
126+
@ldap_result && @ldap_result[:serverSaslCreds]
127+
end
122128

123129
#
124130
# parse_ldap_result

0 commit comments

Comments
 (0)