class AutomateIt::AccountManager::Etc

AccountManager::Etc

An AccountManager driver for Unix-like OSes that have the Ruby Etc module. It is only suitable for doing queries and lacks methods that perform modifications, such as add_user. Platform-specific drivers inherit from this class and provide methods that perform modifications.

Public Instance Methods

groups() click to toggle source

See AccountManager#groups

# File lib/automateit/account_manager/etc.rb, line 80
def groups
  return GroupQuery.new
end
groups_for_user(query) click to toggle source

See AccountManager#groups_for_user

# File lib/automateit/account_manager/etc.rb, line 90
def groups_for_user(query)
  pwent = users[query]
  return [] if preview? and not pwent
  username = pwent.name
  result = Set.new
  result << groups[pwent.gid].name if groups[pwent.gid]
  ::Etc.group do |grent|
    result << grent.name if grent.mem.include?(username)
  end
  return result.to_a
end
has_group?(query) click to toggle source

See AccountManager#has_group?

# File lib/automateit/account_manager/etc.rb, line 85
def has_group?(query)
  return ! groups[query].nil?
end
has_user?(query) click to toggle source

See AccountManager#has_user?

# File lib/automateit/account_manager/etc.rb, line 51
def has_user?(query)
  return ! users[query].nil?
end
users() click to toggle source

See AccountManager#users

# File lib/automateit/account_manager/etc.rb, line 46
def users
  return UserQuery.new
end
users_for_group(query) click to toggle source

See AccountManager#users_for_group

# File lib/automateit/account_manager/etc.rb, line 103
def users_for_group(query)
  grent = groups[query]
  return (preview? || ! grent) ? [] : grent.mem
end
users_to_groups() click to toggle source

See AccountManager#users_to_groups

# File lib/automateit/account_manager/etc.rb, line 109
def users_to_groups
  result = {}
  ::Etc.group do |grent|
    grent.mem.each do |username|
      result[username] ||= Set.new
      result[username] << grent.name
    end
  end
  ::Etc.passwd do |pwent|
    grent = groups[pwent.gid]
    unless grent
      log.fatal(PNOTE+"WARNING: User's default group doesn't exist: user %s, gid %s" % [pwent.name, pwent.gid])
      next
    end
    result[pwent.name] ||= Set.new
    result[pwent.name] << grent.name
  end
  return result
end