Class | AutomateIt::AccountManager::POSIX |
In: |
lib/automateit/account_manager/posix.rb
|
Parent: | ::AutomateIt::AccountManager::BaseDriver |
A POSIX driver for the AccountManager.
# File lib/automateit/account_manager/posix.rb, line 68 def add_group(groupname, opts={}) modified = false unless has_group?(groupname) modified = true cmd = "groupadd" cmd << " -g #{opts[:gid]}" if opts[:gid] cmd << " #{groupname}" interpreter.sh(cmd) manager.invalidate(:groups) end if opts[:members] modified = true add_users_to_group(opts[:members], groupname) end return modified ? groups[groupname] : false end
See AccountManager#add_groups_to_user
# File lib/automateit/account_manager/posix.rb, line 47 def add_groups_to_user(groups, username) return _add_groups_to_user_helper(groups, username) do |missing, username| targets = (groups_for_user(username) + missing).uniq cmd = "usermod -G #{targets.join(',')} #{username}" interpreter.sh(cmd) end end
# File lib/automateit/account_manager/posix.rb, line 15 def add_user(username, opts={}) return _add_user_helper(username, opts) do |username, opts| cmd = "useradd" cmd << " -c #{opts[:description] || username}" cmd << " -d #{opts[:home]}" if opts[:home] cmd << " -m" unless opts[:create_home] == false cmd << " -G #{opts[:groups].join(',')}" if opts[:groups] cmd << " -s #{opts[:shell] || "/bin/bash"}" cmd << " -u #{opts[:uid]}" if opts[:uid] cmd << " -g #{opts[:gid]}" if opts[:gid] cmd << " #{username} < /dev/null" cmd << " > /dev/null 2>&1 | grep -v blocks" if opts[:quiet] interpreter.sh(cmd) end end
See AccountManager#add_users_to_group
# File lib/automateit/account_manager/posix.rb, line 104 def add_users_to_group(users, groupname) _add_users_to_group_helper(users, groupname) do |missing, groupname| for username in missing targets = (groups_for_user(username) + [groupname]).uniq cmd = "usermod -G #{targets.join(',')} #{username}" interpreter.sh(cmd) end end end
Dispatch common names to Etc, but don‘t define these methods here because that would make available? and suitability think these exist, when in fact, they‘re just wrappers.
# File lib/automateit/account_manager/posix.rb, line 130 def method_missing(symbol, *args, &block) case symbol when :users, :has_user?, :groups, :has_group?, :groups_for_user, :users_for_group, :users_to_groups manager.send(symbol, *args, &block) else super(symbol, *args, &block) end end
See AccountManager#remove_group
# File lib/automateit/account_manager/posix.rb, line 93 def remove_group(groupname, opts={}) return false unless has_group?(groupname) cmd = "groupdel #{groupname}" interpreter.sh(cmd) manager.invalidate(:groups) return true end
See AccountManager#remove_groups_from_user
# File lib/automateit/account_manager/posix.rb, line 57 def remove_groups_from_user(groups, username) return _remove_groups_from_user_helper(groups, username) do |present, username| matches = (groups_for_user(username) - [groups].flatten).uniq cmd = "usermod -G #{matches.join(',')} #{username}" interpreter.sh(cmd) end end
See AccountManager#remove_user
# File lib/automateit/account_manager/posix.rb, line 35 def remove_user(username, opts={}) return _remove_user_helper(username, opts) do |username, opts| # Options: -r -- remove the home directory and mail spool cmd = "userdel" cmd << " -r" unless opts[:remove_home] == false cmd << " #{username}" cmd << " > /dev/null" if opts[:quiet] interpreter.sh(cmd) end end
See AccountManager#remove_users_from_group
# File lib/automateit/account_manager/posix.rb, line 115 def remove_users_from_group(users, groupname) _remove_users_from_group_helper(users, groupname) do |present, groupname| u2g = users_to_groups for username in present user_groups = u2g[username] # FIXME tries to include non-present groups, should use some variant of present cmd = "usermod -G #{(user_groups.to_a-[groupname]).join(',')} #{username}" interpreter.sh(cmd) end end end