diff --git a/lib/ldap_fluff/posix_member_service.rb b/lib/ldap_fluff/posix_member_service.rb index 440b2c2..e80b7ad 100644 --- a/lib/ldap_fluff/posix_member_service.rb +++ b/lib/ldap_fluff/posix_member_service.rb @@ -15,17 +15,35 @@ def find_user(uid, base_dn = @base) # return an ldap user with groups attached # note : this method is not particularly fast for large ldap systems + # This group will check all the groups and will match the user. MemberOf plugin + # it's not required for this operation, once this plugin it's optional in ldap. def find_user_groups(uid) groups = [] - @ldap.search( - :filter => Net::LDAP::Filter.eq('memberuid', uid), - :base => @group_base, :attributes => ["cn"] - ).each do |entry| - groups << entry[:cn][0] + + search_filter = Net::LDAP::Filter.eq('objectClass', 'groupOfNames') + results_attr = ["cn", "member"] + + ldap.search(:filter => search_filter, :attributes => results_attr).each do |grp_info| + + grp_info[:member].each do |login| + only_uid = login.split(',')[0].split('=')[1] + + if only_uid.include?(uid) + groups << grp_info[:cn] + end + end + end + + if groups.length > 0 + groups.flatten! + else + groups = [] end - groups end + + + def times_in_groups(uid, gids, all) filters = [] gids.each do |cn|