Skip to content

Commit 470feed

Browse files
committed
Fix GSS_SPNEGO auth adapter
1 parent 3bf849d commit 470feed

File tree

5 files changed

+15
-12
lines changed

5 files changed

+15
-12
lines changed

lib/net/ldap.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class LDAP
3333

3434
Net::LDAP::AuthAdapter.register([:simple, :anon, :anonymous], Net::LDAP::AuthAdapter::Simple)
3535
Net::LDAP::AuthAdapter.register(:sasl, Net::LDAP::AuthAdapter::Sasl)
36+
Net::LDAP::AuthAdapter.register(:gss_spnego, Net::LDAP::AuthAdapter::GssSpnego)
3637

3738
# == Quick-start for the Impatient
3839
# === Quick Example of a user-authentication against an LDAP directory:

lib/net/ldap/auth_adapter/gss_spnego.rb

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
module Net
55
class LDAP
6-
module AuthAdapers
6+
class AuthAdapter
77
#--
88
# PROVISIONAL, only for testing SASL implementations. DON'T USE THIS YET.
99
# Uses Kohei Kajimoto's Ruby/NTLM. We have to find a clean way to
@@ -15,25 +15,25 @@ module AuthAdapers
1515
# GSS-SPNEGO authentication with the server, which is presumed to be a
1616
# Microsoft Active Directory.
1717
#++
18-
class GSS_SPNEGO < Net::LDAP::AuthAdapter
18+
class GssSpnego < Net::LDAP::AuthAdapter
1919
def bind(auth)
20-
require 'ntlm'
21-
22-
user, psw = [auth[:username] || auth[:dn], auth[:password]]
23-
raise Net::LDAP::BindingInformationInvalidError, "Invalid binding information" unless (user && psw)
20+
user = auth[:username] || auth[:dn]
21+
psw = auth[:password]
22+
fail Net::LDAP::BindingInformationInvalidError, "Invalid binding information" unless (user && psw)
2423

2524
nego = proc do |challenge|
2625
t2_msg = NTLM::Message.parse(challenge)
2726
t3_msg = t2_msg.response({ :user => user, :password => psw },
28-
{ :ntlmv2 => true })
27+
:ntlmv2 => true)
2928
t3_msg.serialize
3029
end
3130

32-
Net::LDAP::AuthAdapter::Sasl.new(@connection).bind \
33-
:method => :sasl,
34-
:mechanism => "GSS-SPNEGO",
31+
Net::LDAP::AuthAdapter::Sasl.new(@connection).bind(
32+
:method => :sasl,
33+
:mechanism => "GSS-SPNEGO",
3534
:initial_credential => NTLM::Message::Type1.new.serialize,
3635
:challenge_response => nego
36+
)
3737
end
3838
end
3939
end

lib/net/ldap/auth_adapter/sasl.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ module Net
44
class LDAP
55
class AuthAdapter
66
class Sasl < Net::LDAP::AuthAdapter
7+
8+
MAX_SASL_CHALLENGES = 10
79
#--
810
# Required parameters: :mechanism, :initial_credential and
911
# :challenge_response
@@ -47,7 +49,7 @@ def bind(auth)
4749
end
4850

4951
return pdu unless pdu.result_code == Net::LDAP::ResultCodeSaslBindInProgress
50-
raise Net::LDAP::SASLChallengeOverflowError, "sasl-challenge overflow" if ((n += 1) > MaxSaslChallenges)
52+
raise Net::LDAP::SASLChallengeOverflowError, "sasl-challenge overflow" if ((n += 1) > MAX_SASL_CHALLENGES)
5153

5254
cred = chall.call(pdu.result_server_sasl_creds)
5355
end

lib/net/ldap/connection.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ class Net::LDAP::Connection #:nodoc:
77
DefaultConnectTimeout = 5
88

99
LdapVersion = 3
10-
MaxSaslChallenges = 10
1110

1211
# Initialize a connection to an LDAP server
1312
#

net-ldap.gemspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ the most recent LDAP RFCs (4510-4519, plutions of 4520-4532).}
2929
s.required_ruby_version = ">= 2.0.0"
3030
s.summary = %q{Net::LDAP for Ruby (also called net-ldap) implements client access for the Lightweight Directory Access Protocol (LDAP), an IETF standard protocol for accessing distributed directory services}
3131

32+
s.add_runtime_dependency("rubyntlm")
3233
s.add_development_dependency("flexmock", "~> 1.3")
3334
s.add_development_dependency("rake", "~> 10.0")
3435
s.add_development_dependency("rubocop", "~> 0.28.0")

0 commit comments

Comments
 (0)