ldap_fluff 0.5.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.rdoc +7 -1
- data/lib/ldap_fluff/active_directory.rb +5 -7
- data/lib/ldap_fluff/ad_member_service.rb +38 -16
- data/lib/ldap_fluff/config.rb +6 -6
- data/lib/ldap_fluff/error.rb +0 -1
- data/lib/ldap_fluff/freeipa.rb +4 -7
- data/lib/ldap_fluff/freeipa_member_service.rb +1 -4
- data/lib/ldap_fluff/freeipa_netgroup_member_service.rb +0 -2
- data/lib/ldap_fluff/generic.rb +9 -9
- data/lib/ldap_fluff/generic_member_service.rb +2 -4
- data/lib/ldap_fluff/ldap_fluff.rb +11 -9
- data/lib/ldap_fluff/netiq.rb +6 -0
- data/lib/ldap_fluff/netiq_member_service.rb +43 -0
- data/lib/ldap_fluff/posix.rb +9 -10
- data/lib/ldap_fluff/posix_member_service.rb +4 -24
- data/lib/ldap_fluff/posix_netgroup_member_service.rb +0 -2
- data/lib/ldap_fluff.rb +2 -0
- data/test/ad_member_services_test.rb +20 -5
- data/test/ad_test.rb +33 -34
- data/test/config_test.rb +6 -6
- data/test/ipa_member_services_test.rb +3 -4
- data/test/ipa_netgroup_member_services_test.rb +1 -2
- data/test/ipa_test.rb +25 -27
- data/test/ldap_test.rb +9 -12
- data/test/lib/ldap_test_helper.rb +39 -21
- data/test/netiq_member_services_test.rb +81 -0
- data/test/netiq_test.rb +145 -0
- data/test/posix_member_services_test.rb +10 -8
- data/test/posix_netgroup_member_services_test.rb +6 -6
- data/test/posix_test.rb +28 -27
- metadata +45 -24
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 80bbd37fc8123c1481d81117015acae3ba22aaaf95c6d87ef064c124c7f8f6f0
|
4
|
+
data.tar.gz: '0899615a301cc6569a3e036b136f27c73a68accf270aa4842b2bf17164bcf2ac'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c288887b87abb0136d093d61924ddb646234135509cd95bccb4a29c2df149a19855e81eec321cfa3b69a34aeb95934e60c158d088b8a348e7c67d4fb10909334
|
7
|
+
data.tar.gz: 3ba66326d622afcfa64a15adc8ff87398726d38d775ed46c35ebe5e3b4026c3d01731ffcb8768af01ea5cf5ada903a8c5d246816b99fcfc4e7545a29f409fc79
|
data/README.rdoc
CHANGED
@@ -83,6 +83,8 @@ ldap_fluff does not support searching/binding global catalogs
|
|
83
83
|
|
84
84
|
service_user (formatted as "ad_domain/username") and service_pass OR anon_queries are required for AD support
|
85
85
|
|
86
|
+
Group membership searches will use "msds-memberOfTransitive" where possible, and will fall back to a recursive lookup
|
87
|
+
|
86
88
|
=== A note on FreeIPA
|
87
89
|
|
88
90
|
ldap_fluff appends cn=groups,cn=accounts to the beginning of all BIND calls. You do not need to
|
@@ -99,6 +101,10 @@ ActiveSupport::Notifications. ldap_fluff will use this and also pass it to net-
|
|
99
101
|
When using Rails, pass `:instrumentation_service => ActiveSupport::Notifications` and then subscribe to, and
|
100
102
|
optionally log events (e.g. https://gist.github.com/mnutt/566725).
|
101
103
|
|
102
|
-
|
104
|
+
== Contributing
|
105
|
+
|
106
|
+
Feel free to file PR against our github repository.
|
107
|
+
|
108
|
+
== License
|
103
109
|
|
104
110
|
ldap_fluff is licensed under the GPLv2. Please read LICENSE for more information.
|
@@ -1,10 +1,9 @@
|
|
1
1
|
class LdapFluff::ActiveDirectory < LdapFluff::Generic
|
2
|
-
|
3
2
|
def bind?(uid = nil, password = nil, opts = {})
|
4
3
|
unless uid.include?(',') || uid.include?('\\') || opts[:search] == false
|
5
4
|
service_bind
|
6
5
|
user = @member_service.find_user(uid)
|
7
|
-
uid = user.first.dn if user
|
6
|
+
uid = user.first.dn if user&.first
|
8
7
|
end
|
9
8
|
@ldap.auth(uid, password)
|
10
9
|
@ldap.bind
|
@@ -18,9 +17,9 @@ class LdapFluff::ActiveDirectory < LdapFluff::Generic
|
|
18
17
|
begin
|
19
18
|
groups = @member_service.find_user_groups(uid)
|
20
19
|
intersection = gids & groups
|
21
|
-
|
20
|
+
(all ? intersection == gids : intersection.size > 0)
|
22
21
|
rescue MemberService::UIDNotFoundException
|
23
|
-
|
22
|
+
false
|
24
23
|
end
|
25
24
|
end
|
26
25
|
|
@@ -37,14 +36,13 @@ class LdapFluff::ActiveDirectory < LdapFluff::Generic
|
|
37
36
|
end
|
38
37
|
objectclasses = entry.objectclass.map(&:downcase)
|
39
38
|
|
40
|
-
if (%w
|
39
|
+
if (%w[organizationalperson person userproxy] & objectclasses).present?
|
41
40
|
users << @member_service.get_login_from_entry(entry)
|
42
|
-
elsif (%w
|
41
|
+
elsif (%w[organizationalunit group] & objectclasses).present?
|
43
42
|
users << users_for_gid(entry.cn.first)
|
44
43
|
end
|
45
44
|
end
|
46
45
|
|
47
46
|
users.flatten.uniq
|
48
47
|
end
|
49
|
-
|
50
48
|
end
|
@@ -2,26 +2,49 @@ require 'net/ldap'
|
|
2
2
|
|
3
3
|
# Naughty bits of active directory ldap queries
|
4
4
|
class LdapFluff::ActiveDirectory::MemberService < LdapFluff::GenericMemberService
|
5
|
-
|
6
5
|
def initialize(ldap, config)
|
7
6
|
@attr_login = (config.attr_login || 'samaccountname')
|
8
7
|
super
|
9
8
|
end
|
10
9
|
|
11
10
|
# get a list [] of ldap groups for a given user
|
12
|
-
#
|
11
|
+
# try to use msds-memberOfTransitive if it is supported, otherwise do a recursive loop
|
13
12
|
def find_user_groups(uid)
|
14
|
-
|
15
|
-
|
13
|
+
user_data = find_user(uid).first
|
14
|
+
|
15
|
+
if _get_domain_func_level >= 6
|
16
|
+
user_dn = user_data[:distinguishedname].first
|
17
|
+
search = @ldap.search(:base => user_dn, :scope => Net::LDAP::SearchScope_BaseObject, :attributes => ['msds-memberOfTransitive'])
|
18
|
+
if !search.nil? && !search.first.nil?
|
19
|
+
return get_groups(search.first['msds-memberoftransitive'])
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
# Fall back to recursive lookup
|
24
|
+
_groups_from_ldap_data(user_data)
|
25
|
+
end
|
26
|
+
|
27
|
+
# return the domain functionality level, default to 0
|
28
|
+
def _get_domain_func_level
|
29
|
+
return @domain_functionality if defined?(@domain_functionality)
|
30
|
+
|
31
|
+
@domain_functionality = 0
|
32
|
+
|
33
|
+
search = @ldap.search(:base => "", :scope => Net::LDAP::SearchScope_BaseObject, :attributes => ['domainFunctionality'])
|
34
|
+
if !search.nil? && !search.first.nil?
|
35
|
+
@domain_functionality = search.first[:domainfunctionality].first.to_i
|
36
|
+
end
|
37
|
+
|
38
|
+
@domain_functionality
|
16
39
|
end
|
17
40
|
|
18
41
|
# return the :memberof attrs + parents, recursively
|
19
42
|
def _groups_from_ldap_data(payload)
|
20
43
|
data = []
|
21
|
-
|
22
|
-
first_level
|
23
|
-
total_groups,
|
24
|
-
data
|
44
|
+
unless payload.nil?
|
45
|
+
first_level = payload[:memberof]
|
46
|
+
total_groups, = _walk_group_ancestry(first_level, first_level)
|
47
|
+
data = get_groups(first_level + total_groups).uniq
|
25
48
|
end
|
26
49
|
data
|
27
50
|
end
|
@@ -31,14 +54,13 @@ class LdapFluff::ActiveDirectory::MemberService < LdapFluff::GenericMemberServic
|
|
31
54
|
set = []
|
32
55
|
group_dns.each do |group_dn|
|
33
56
|
search = @ldap.search(:base => group_dn, :scope => Net::LDAP::SearchScope_BaseObject, :attributes => ['memberof'])
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
end
|
57
|
+
next unless !search.nil? && !search.first.nil?
|
58
|
+
groups = search.first[:memberof] - known_groups
|
59
|
+
known_groups += groups
|
60
|
+
next_level, _new_known_groups = _walk_group_ancestry(groups, known_groups)
|
61
|
+
set += next_level
|
62
|
+
set += groups
|
63
|
+
known_groups += next_level
|
42
64
|
end
|
43
65
|
[set, known_groups]
|
44
66
|
end
|
data/lib/ldap_fluff/config.rb
CHANGED
@@ -3,8 +3,8 @@ require 'active_support/core_ext/hash'
|
|
3
3
|
|
4
4
|
class LdapFluff::Config
|
5
5
|
ATTRIBUTES = %w[host port encryption base_dn group_base server_type service_user
|
6
|
-
|
7
|
-
|
6
|
+
service_pass anon_queries attr_login search_filter
|
7
|
+
instrumentation_service use_netgroups].freeze
|
8
8
|
ATTRIBUTES.each { |attr| attr_reader attr.to_sym }
|
9
9
|
|
10
10
|
DEFAULT_CONFIG = { 'port' => 389,
|
@@ -14,7 +14,7 @@ class LdapFluff::Config
|
|
14
14
|
'server_type' => :free_ipa,
|
15
15
|
'anon_queries' => false,
|
16
16
|
'instrumentation_service' => nil,
|
17
|
-
'use_netgroups' => false }
|
17
|
+
'use_netgroups' => false }.freeze
|
18
18
|
|
19
19
|
def initialize(config)
|
20
20
|
raise ArgumentError unless config.respond_to?(:to_hash)
|
@@ -65,9 +65,9 @@ class LdapFluff::Config
|
|
65
65
|
end
|
66
66
|
|
67
67
|
def correct_server_type?(config)
|
68
|
-
unless [
|
69
|
-
raise ConfigError, 'config key server_type has to be :active_directory, :posix, :free_ipa ' +
|
70
|
-
|
68
|
+
unless %i[posix active_directory free_ipa netiq].include?(config['server_type'])
|
69
|
+
raise ConfigError, 'config key server_type has to be :active_directory, :posix, :free_ipa, :netiq ' +
|
70
|
+
"but was #{config['server_type']}"
|
71
71
|
end
|
72
72
|
end
|
73
73
|
|
data/lib/ldap_fluff/error.rb
CHANGED
data/lib/ldap_fluff/freeipa.rb
CHANGED
@@ -1,23 +1,20 @@
|
|
1
1
|
class LdapFluff::FreeIPA < LdapFluff::Generic
|
2
|
-
|
3
2
|
def bind?(uid = nil, password = nil, opts = {})
|
4
3
|
unless uid.include?(',')
|
5
4
|
unless opts[:search] == false
|
6
5
|
service_bind
|
7
6
|
user = @member_service.find_user(uid)
|
8
7
|
end
|
9
|
-
uid = user
|
8
|
+
uid = user&.first ? user.first.dn : "uid=#{uid},cn=users,cn=accounts,#{@base}"
|
10
9
|
end
|
11
10
|
@ldap.auth(uid, password)
|
12
11
|
@ldap.bind
|
13
12
|
end
|
14
13
|
|
15
14
|
def groups_for_uid(uid)
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
raise UnauthenticatedException, "Insufficient Privileges to query groups data"
|
20
|
-
end
|
15
|
+
super
|
16
|
+
rescue MemberService::InsufficientQueryPrivilegesException
|
17
|
+
raise UnauthenticatedException, "Insufficient Privileges to query groups data"
|
21
18
|
end
|
22
19
|
|
23
20
|
private
|
@@ -1,7 +1,6 @@
|
|
1
1
|
require 'net/ldap'
|
2
2
|
|
3
3
|
class LdapFluff::FreeIPA::MemberService < LdapFluff::GenericMemberService
|
4
|
-
|
5
4
|
def initialize(ldap, config)
|
6
5
|
@attr_login = (config.attr_login || 'uid')
|
7
6
|
super
|
@@ -23,7 +22,7 @@ class LdapFluff::FreeIPA::MemberService < LdapFluff::GenericMemberService
|
|
23
22
|
# CN=bros,OU=bropeeps,DC=jomara,DC=redhat,DC=com
|
24
23
|
def get_groups(grouplist)
|
25
24
|
grouplist.map(&:downcase).collect do |g|
|
26
|
-
if
|
25
|
+
if /.*?ipauniqueid=(.*?)/.match?(g)
|
27
26
|
@ldap.search(:base => g)[0][:cn][0]
|
28
27
|
else
|
29
28
|
g.sub(/.*?cn=(.*?),.*/, '\1')
|
@@ -39,6 +38,4 @@ class LdapFluff::FreeIPA::MemberService < LdapFluff::GenericMemberService
|
|
39
38
|
|
40
39
|
class InsufficientQueryPrivilegesException < LdapFluff::Error
|
41
40
|
end
|
42
|
-
|
43
41
|
end
|
44
|
-
|
@@ -1,7 +1,6 @@
|
|
1
1
|
require 'net/ldap'
|
2
2
|
|
3
3
|
class LdapFluff::FreeIPA::NetgroupMemberService < LdapFluff::FreeIPA::MemberService
|
4
|
-
|
5
4
|
def find_user_groups(uid)
|
6
5
|
groups = []
|
7
6
|
@ldap.search(:filter => Net::LDAP::Filter.eq('objectClass', 'nisNetgroup'), :base => @group_base).each do |entry|
|
@@ -11,4 +10,3 @@ class LdapFluff::FreeIPA::NetgroupMemberService < LdapFluff::FreeIPA::MemberServ
|
|
11
10
|
groups
|
12
11
|
end
|
13
12
|
end
|
14
|
-
|
data/lib/ldap_fluff/generic.rb
CHANGED
@@ -7,9 +7,9 @@ class LdapFluff::Generic
|
|
7
7
|
:port => config.port,
|
8
8
|
:encryption => config.encryption,
|
9
9
|
:instrumentation_service => config.instrumentation_service)
|
10
|
-
@bind_user
|
11
|
-
@bind_pass
|
12
|
-
@anon
|
10
|
+
@bind_user = config.service_user
|
11
|
+
@bind_pass = config.service_pass
|
12
|
+
@anon = config.anon_queries
|
13
13
|
@attr_login = config.attr_login
|
14
14
|
@base = config.base_dn
|
15
15
|
@group_base = (config.group_base.empty? ? config.base_dn : config.group_base)
|
@@ -37,7 +37,7 @@ class LdapFluff::Generic
|
|
37
37
|
service_bind
|
38
38
|
@member_service.find_user_groups(uid)
|
39
39
|
rescue self.class::MemberService::UIDNotFoundException
|
40
|
-
|
40
|
+
[]
|
41
41
|
end
|
42
42
|
|
43
43
|
def users_for_gid(gid)
|
@@ -60,9 +60,9 @@ class LdapFluff::Generic
|
|
60
60
|
groups = @member_service.find_user_groups(uid).sort
|
61
61
|
gids = gids.sort
|
62
62
|
if all
|
63
|
-
|
63
|
+
groups & gids == gids
|
64
64
|
else
|
65
|
-
|
65
|
+
(groups & gids).any?
|
66
66
|
end
|
67
67
|
end
|
68
68
|
|
@@ -74,16 +74,17 @@ class LdapFluff::Generic
|
|
74
74
|
def service_bind
|
75
75
|
unless @anon || bind?(@bind_user, @bind_pass, :search => false)
|
76
76
|
raise UnauthenticatedException,
|
77
|
-
|
77
|
+
"Could not bind to #{class_name} user #{@bind_user}"
|
78
78
|
end
|
79
79
|
end
|
80
80
|
|
81
81
|
private
|
82
|
+
|
82
83
|
def select_member_method(search_result)
|
83
84
|
if @use_netgroups
|
84
85
|
:nisnetgrouptriple
|
85
86
|
else
|
86
|
-
[
|
87
|
+
%i[member memberuid uniquemember].find { |m| search_result.respond_to? m }
|
87
88
|
end
|
88
89
|
end
|
89
90
|
|
@@ -114,4 +115,3 @@ class LdapFluff::Generic
|
|
114
115
|
class UnauthenticatedException < LdapFluff::Error
|
115
116
|
end
|
116
117
|
end
|
117
|
-
|
@@ -1,7 +1,6 @@
|
|
1
1
|
require 'net/ldap'
|
2
2
|
|
3
3
|
class LdapFluff::GenericMemberService
|
4
|
-
|
5
4
|
attr_accessor :ldap
|
6
5
|
|
7
6
|
def initialize(ldap, config)
|
@@ -11,8 +10,8 @@ class LdapFluff::GenericMemberService
|
|
11
10
|
@search_filter = nil
|
12
11
|
begin
|
13
12
|
@search_filter = Net::LDAP::Filter.construct(config.search_filter) unless (config.search_filter.nil? || config.search_filter.empty?)
|
14
|
-
rescue Net::LDAP::Error =>
|
15
|
-
puts "Search filter unavailable - #{
|
13
|
+
rescue Net::LDAP::Error => e
|
14
|
+
puts "Search filter unavailable - #{e}"
|
16
15
|
end
|
17
16
|
end
|
18
17
|
|
@@ -81,5 +80,4 @@ class LdapFluff::GenericMemberService
|
|
81
80
|
end
|
82
81
|
nil
|
83
82
|
end
|
84
|
-
|
85
83
|
end
|
@@ -13,6 +13,8 @@ class LdapFluff
|
|
13
13
|
@ldap = ActiveDirectory.new(config)
|
14
14
|
when :free_ipa
|
15
15
|
@ldap = FreeIPA.new(config)
|
16
|
+
when :netiq
|
17
|
+
@ldap = NetIQ.new(config)
|
16
18
|
else
|
17
19
|
raise 'unknown server_type'
|
18
20
|
end
|
@@ -20,7 +22,7 @@ class LdapFluff
|
|
20
22
|
end
|
21
23
|
|
22
24
|
def authenticate?(uid, password)
|
23
|
-
instrument('authenticate.ldap_fluff', :uid => uid) do |
|
25
|
+
instrument('authenticate.ldap_fluff', :uid => uid) do |_payload|
|
24
26
|
if password.nil? || password.empty?
|
25
27
|
false
|
26
28
|
else
|
@@ -30,21 +32,21 @@ class LdapFluff
|
|
30
32
|
end
|
31
33
|
|
32
34
|
def test
|
33
|
-
instrument('test.ldap_fluff') do |
|
35
|
+
instrument('test.ldap_fluff') do |_payload|
|
34
36
|
@ldap.ldap.open {}
|
35
37
|
end
|
36
38
|
end
|
37
39
|
|
38
40
|
# return a list[] of users for a given gid
|
39
41
|
def user_list(gid)
|
40
|
-
instrument('user_list.ldap_fluff', :gid => gid) do |
|
42
|
+
instrument('user_list.ldap_fluff', :gid => gid) do |_payload|
|
41
43
|
@ldap.users_for_gid(gid)
|
42
44
|
end
|
43
45
|
end
|
44
46
|
|
45
47
|
# return a list[] of groups for a given uid
|
46
48
|
def group_list(uid)
|
47
|
-
instrument('group_list.ldap_fluff', :uid => uid) do |
|
49
|
+
instrument('group_list.ldap_fluff', :uid => uid) do |_payload|
|
48
50
|
@ldap.groups_for_uid(uid)
|
49
51
|
end
|
50
52
|
end
|
@@ -52,35 +54,35 @@ class LdapFluff
|
|
52
54
|
# return true if a user is in all of the groups
|
53
55
|
# in grouplist
|
54
56
|
def is_in_groups?(uid, grouplist)
|
55
|
-
instrument('is_in_groups?.ldap_fluff', :uid => uid, :grouplist => grouplist) do |
|
57
|
+
instrument('is_in_groups?.ldap_fluff', :uid => uid, :grouplist => grouplist) do |_payload|
|
56
58
|
@ldap.is_in_groups(uid, grouplist, true)
|
57
59
|
end
|
58
60
|
end
|
59
61
|
|
60
62
|
# return true if uid exists
|
61
63
|
def valid_user?(uid)
|
62
|
-
instrument('valid_user?.ldap_fluff', :uid => uid) do |
|
64
|
+
instrument('valid_user?.ldap_fluff', :uid => uid) do |_payload|
|
63
65
|
@ldap.user_exists? uid
|
64
66
|
end
|
65
67
|
end
|
66
68
|
|
67
69
|
# return true if group exists
|
68
70
|
def valid_group?(gid)
|
69
|
-
instrument('valid_group?.ldap_fluff', :gid => gid) do |
|
71
|
+
instrument('valid_group?.ldap_fluff', :gid => gid) do |_payload|
|
70
72
|
@ldap.group_exists? gid
|
71
73
|
end
|
72
74
|
end
|
73
75
|
|
74
76
|
# return ldap entry
|
75
77
|
def find_user(uid)
|
76
|
-
instrument('find_user.ldap_fluff', :uid => uid) do |
|
78
|
+
instrument('find_user.ldap_fluff', :uid => uid) do |_payload|
|
77
79
|
@ldap.member_service.find_user(uid)
|
78
80
|
end
|
79
81
|
end
|
80
82
|
|
81
83
|
# return ldap entry
|
82
84
|
def find_group(gid)
|
83
|
-
instrument('find_group.ldap_fluff', :gid => gid) do |
|
85
|
+
instrument('find_group.ldap_fluff', :gid => gid) do |_payload|
|
84
86
|
@ldap.member_service.find_group(gid)
|
85
87
|
end
|
86
88
|
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'net/ldap'
|
2
|
+
|
3
|
+
# handles the naughty bits of posix ldap
|
4
|
+
class LdapFluff::NetIQ::MemberService < LdapFluff::Posix::MemberService
|
5
|
+
def initialize(ldap, config)
|
6
|
+
super
|
7
|
+
# set default after super, because Posix' initialize would overwrite it otherwise
|
8
|
+
@attr_login = (config.attr_login || 'uid')
|
9
|
+
end
|
10
|
+
|
11
|
+
def find_by_dn(search_dn)
|
12
|
+
entry, base = search_dn.split(/(?<!\\),/, 2)
|
13
|
+
_entry_attr, entry_value = entry.split('=', 2)
|
14
|
+
entry_value = entry_value.gsub('\,', ',')
|
15
|
+
user = @ldap.search(:filter => name_filter(entry_value, 'workforceid'), :base => base)
|
16
|
+
raise self.class::UIDNotFoundException if (user.nil? || user.empty?)
|
17
|
+
user
|
18
|
+
end
|
19
|
+
|
20
|
+
def get_logins(userlist)
|
21
|
+
userlist.map do |current_user|
|
22
|
+
find_by_dn(current_user&.downcase)[0][@attr_login][0]
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
# return an ldap user with groups attached
|
27
|
+
# note : this method is not particularly fast for large ldap systems
|
28
|
+
def find_user_groups(uid)
|
29
|
+
filter = Net::LDAP::Filter.eq('memberuid', uid)
|
30
|
+
begin
|
31
|
+
user = find_user(uid)[0][:dn][0]
|
32
|
+
filter |= Net::LDAP::Filter.eq('member', user)
|
33
|
+
rescue UIDNotFoundException
|
34
|
+
# do nothing
|
35
|
+
end
|
36
|
+
|
37
|
+
@ldap.search(
|
38
|
+
:filter => filter,
|
39
|
+
:base => @group_base,
|
40
|
+
:attributes => ['cn']
|
41
|
+
).map { |entry| entry[:cn][0] }
|
42
|
+
end
|
43
|
+
end
|
data/lib/ldap_fluff/posix.rb
CHANGED
@@ -1,10 +1,9 @@
|
|
1
1
|
class LdapFluff::Posix < LdapFluff::Generic
|
2
|
-
|
3
2
|
def bind?(uid = nil, password = nil, opts = {})
|
4
3
|
unless uid.include?(',') || opts[:search] == false
|
5
4
|
service_bind
|
6
5
|
user = @member_service.find_user(uid)
|
7
|
-
uid = user.first.dn if user
|
6
|
+
uid = user.first.dn if user&.first
|
8
7
|
end
|
9
8
|
@ldap.auth(uid, password)
|
10
9
|
@ldap.bind
|
@@ -17,14 +16,14 @@ class LdapFluff::Posix < LdapFluff::Generic
|
|
17
16
|
# we have to look for OUs or posixGroups within the current group scope,
|
18
17
|
# i.e: cn=ldapusers,ou=groups,dc=example,dc=com -> cn=myusers,cn=ldapusers,ou=gr...
|
19
18
|
|
20
|
-
if @use_netgroups
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
19
|
+
filter = if @use_netgroups
|
20
|
+
Net::LDAP::Filter.eq('objectClass', 'nisNetgroup')
|
21
|
+
else
|
22
|
+
Net::LDAP::Filter.eq('objectClass', 'posixGroup') |
|
23
|
+
Net::LDAP::Filter.eq('objectClass', 'organizationalunit') |
|
24
|
+
Net::LDAP::Filter.eq('objectClass', 'groupOfUniqueNames') |
|
25
|
+
Net::LDAP::Filter.eq('objectClass', 'groupOfNames')
|
26
|
+
end
|
28
27
|
groups = @ldap.search(:base => search.dn, :filter => filter)
|
29
28
|
members = groups.map { |group| group.send(method) }.flatten.uniq
|
30
29
|
|
@@ -2,7 +2,6 @@ require 'net/ldap'
|
|
2
2
|
|
3
3
|
# handles the naughty bits of posix ldap
|
4
4
|
class LdapFluff::Posix::MemberService < LdapFluff::GenericMemberService
|
5
|
-
|
6
5
|
def initialize(ldap, config)
|
7
6
|
@attr_login = (config.attr_login || 'memberuid')
|
8
7
|
super
|
@@ -18,37 +17,18 @@ class LdapFluff::Posix::MemberService < LdapFluff::GenericMemberService
|
|
18
17
|
# note : this method is not particularly fast for large ldap systems
|
19
18
|
def find_user_groups(uid)
|
20
19
|
groups = []
|
21
|
-
@ldap.search(
|
20
|
+
@ldap.search(
|
21
|
+
:filter => Net::LDAP::Filter.eq('memberuid', uid),
|
22
|
+
:base => @group_base, :attributes => ["cn"]
|
23
|
+
).each do |entry|
|
22
24
|
groups << entry[:cn][0]
|
23
25
|
end
|
24
26
|
groups
|
25
27
|
end
|
26
28
|
|
27
|
-
def times_in_groups(uid, gids, all)
|
28
|
-
filters = []
|
29
|
-
gids.each do |cn|
|
30
|
-
filters << group_filter(cn)
|
31
|
-
end
|
32
|
-
group_filters = merge_filters(filters, all)
|
33
|
-
filter = name_filter(uid) & group_filters
|
34
|
-
@ldap.search(:base => @group_base, :filter => filter).size
|
35
|
-
end
|
36
|
-
|
37
|
-
# AND or OR all of the filters together
|
38
|
-
def merge_filters(filters = [], all = false)
|
39
|
-
if !filters.nil? && filters.size >= 1
|
40
|
-
filter = filters[0]
|
41
|
-
filters[1..(filters.size - 1)].each do |gfilter|
|
42
|
-
filter = (all ? filter & gfilter : filter | gfilter)
|
43
|
-
end
|
44
|
-
return filter
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
29
|
class UIDNotFoundException < LdapFluff::Error
|
49
30
|
end
|
50
31
|
|
51
32
|
class GIDNotFoundException < LdapFluff::Error
|
52
33
|
end
|
53
|
-
|
54
34
|
end
|
@@ -2,7 +2,6 @@ require 'net/ldap'
|
|
2
2
|
|
3
3
|
# handles the naughty bits of posix ldap
|
4
4
|
class LdapFluff::Posix::NetgroupMemberService < LdapFluff::Posix::MemberService
|
5
|
-
|
6
5
|
# return list of group CNs for a user
|
7
6
|
def find_user_groups(uid)
|
8
7
|
groups = []
|
@@ -12,5 +11,4 @@ class LdapFluff::Posix::NetgroupMemberService < LdapFluff::Posix::MemberService
|
|
12
11
|
end
|
13
12
|
groups
|
14
13
|
end
|
15
|
-
|
16
14
|
end
|
data/lib/ldap_fluff.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'lib/ldap_test_helper'
|
2
2
|
|
3
|
-
class TestADMemberService <
|
3
|
+
class TestADMemberService < Minitest::Test
|
4
4
|
include LdapTestHelper
|
5
5
|
|
6
6
|
def setup
|
@@ -11,6 +11,7 @@ class TestADMemberService < MiniTest::Test
|
|
11
11
|
|
12
12
|
def basic_user
|
13
13
|
@ldap.expect(:search, ad_user_payload, [:filter => ad_name_filter("john")])
|
14
|
+
@ldap.expect(:search, [{ :domainfunctionality => ['5'] }], [:base => "", :scope => 0, :attributes => ['domainFunctionality']])
|
14
15
|
@ldap.expect(:search, ad_parent_payload(1), [:base => ad_group_dn, :scope => 0, :attributes => ['memberof']])
|
15
16
|
end
|
16
17
|
|
@@ -20,7 +21,7 @@ class TestADMemberService < MiniTest::Test
|
|
20
21
|
|
21
22
|
def nest_deep(n)
|
22
23
|
# add all the expects
|
23
|
-
1.upto(n-1) do |i|
|
24
|
+
1.upto(n - 1) do |i|
|
24
25
|
@ldap.expect(:search, ad_parent_payload(i + 1), [:base => ad_group_dn("bros#{i}"), :scope => 0, :attributes => ['memberof']])
|
25
26
|
end
|
26
27
|
# terminate or we loop FOREVER
|
@@ -39,11 +40,19 @@ class TestADMemberService < MiniTest::Test
|
|
39
40
|
end
|
40
41
|
end
|
41
42
|
|
43
|
+
def transitive_user
|
44
|
+
ad_transitive_payload = [{ 'msds-memberoftransitive' => [ad_group_dn("bros#1"), ad_group_dn("bros#2"), ad_group_dn("bros#3"), ad_group_dn("bros#4"), ad_group_dn("bros#5")] }]
|
45
|
+
|
46
|
+
@ldap.expect(:search, ad_user_payload('john'), [:filter => ad_name_filter("john")])
|
47
|
+
@ldap.expect(:search, [{ :domainfunctionality => ['6'] }], [:base => "", :scope => 0, :attributes => ['domainFunctionality']])
|
48
|
+
@ldap.expect(:search, ad_transitive_payload, [:base => ad_user_dn("john"), :scope => 0, :attributes => ['msds-memberOfTransitive']])
|
49
|
+
end
|
50
|
+
|
42
51
|
def test_find_user
|
43
52
|
basic_user
|
44
53
|
@ldap.expect(:search, [], [:base => ad_group_dn('bros1'), :scope => 0, :attributes => ['memberof']])
|
45
54
|
@adms.ldap = @ldap
|
46
|
-
assert_equal(%w
|
55
|
+
assert_equal(%w[group bros1], @adms.find_user_groups("john"))
|
47
56
|
@ldap.verify
|
48
57
|
end
|
49
58
|
|
@@ -53,7 +62,7 @@ class TestADMemberService < MiniTest::Test
|
|
53
62
|
# now make 'bros1' be memberof 'group' again
|
54
63
|
@ldap.expect(:search, ad_user_payload, [:base => ad_group_dn('bros1'), :scope => 0, :attributes => ['memberof']])
|
55
64
|
@adms.ldap = @ldap
|
56
|
-
assert_equal(%w
|
65
|
+
assert_equal(%w[group bros1], @adms.find_user_groups("john"))
|
57
66
|
@ldap.verify
|
58
67
|
end
|
59
68
|
|
@@ -82,6 +91,13 @@ class TestADMemberService < MiniTest::Test
|
|
82
91
|
@ldap.verify
|
83
92
|
end
|
84
93
|
|
94
|
+
def test_transitive_groups
|
95
|
+
transitive_user
|
96
|
+
@adms.ldap = @ldap
|
97
|
+
assert_equal(5, @adms.find_user_groups('john').size)
|
98
|
+
@ldap.verify
|
99
|
+
end
|
100
|
+
|
85
101
|
def test_nil_payload
|
86
102
|
assert_equal([], @adms._groups_from_ldap_data(nil))
|
87
103
|
end
|
@@ -160,5 +176,4 @@ class TestADMemberService < MiniTest::Test
|
|
160
176
|
entry = Net::LDAP::Entry.new('Example User')
|
161
177
|
assert_nil(@adms.get_login_from_entry(entry))
|
162
178
|
end
|
163
|
-
|
164
179
|
end
|