class LdapFluff::Posix

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
  @group_base ||= config.base
  @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 16
def bind?(uid=nil, password=nil)
  @ldap.auth "uid=#{uid},#{@base}", password
  @ldap.bind
end
groups_for_uid(uid) click to toggle source
# File lib/ldap_fluff/posix.rb, line 21
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 32
def is_in_groups(uid, gids = [], all=true)
  (gids.empty? || @member_service.times_in_groups(uid, gids, all) > 0)
end