class LdapFluff::Posix

Attributes

ldap[RW]
member_service[RW]

Public Class Methods

new(config = {}) click to toggle source
# File lib/ldap_fluff/posix.rb, line 5
def initialize(config = {})
  @ldap           = Net::LDAP.new(:host       => config.host,
                                  :base       => config.base_dn,
                                  :port       => config.port,
                                  :encryption => config.encryption)
  @group_base     = config.group_base || config.base_dn
  @base           = config.base_dn
  @member_service = MemberService.new(@ldap, @group_base)
end

Public Instance Methods

bind?(uid = nil, password = nil) click to toggle source
# File lib/ldap_fluff/posix.rb, line 15
def bind?(uid = nil, password = nil)
  @ldap.bind_as(:filter => "(uid=#{uid})", :password => password)
end
group_exists?(gid) click to toggle source
# File lib/ldap_fluff/posix.rb, line 43
def group_exists?(gid)
  begin
    @member_service.find_group(gid)
  rescue MemberService::GIDNotFoundException
    return false
  end
  return true
end
groups_for_uid(uid) click to toggle source
# File lib/ldap_fluff/posix.rb, line 19
def groups_for_uid(uid)
  @member_service.find_user_groups(uid)
end
is_in_groups(uid, gids = [], all = true) click to toggle source

returns whether a user is a member of ALL or ANY particular groups note: this method is much faster than #groups_for_uid

gids should be an array of group common names

returns true if owner is in ALL of the groups if all=true, otherwise returns true if owner is in ANY of the groups

# File lib/ldap_fluff/posix.rb, line 30
def is_in_groups(uid, gids = [], all = true)
  (gids.empty? || @member_service.times_in_groups(uid, gids, all) > 0)
end
user_exists?(uid) click to toggle source
# File lib/ldap_fluff/posix.rb, line 34
def user_exists?(uid)
  begin
    @member_service.find_user(uid)
  rescue MemberService::UIDNotFoundException
    return false
  end
  return true
end