summaryrefslogtreecommitdiff
path: root/lib/mixlib/shellout.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/mixlib/shellout.rb')
-rw-r--r--lib/mixlib/shellout.rb20
1 files changed, 17 insertions, 3 deletions
diff --git a/lib/mixlib/shellout.rb b/lib/mixlib/shellout.rb
index e0fb3cc..92660c8 100644
--- a/lib/mixlib/shellout.rb
+++ b/lib/mixlib/shellout.rb
@@ -40,8 +40,13 @@ module Mixlib
attr_accessor :user
attr_accessor :domain
attr_accessor :password
+ # TODO remove
attr_accessor :with_logon
+ # Whether to simulate logon as the user. Normally set via options passed to new
+ # Always enabled on windows
+ attr_accessor :login
+
# Group the command will run as. Normally set via options passed to new
attr_accessor :group
@@ -141,6 +146,8 @@ module Mixlib
# child process. Generally this is used to copy data from the child to
# the parent's stdout so that users may observe the progress of
# long-running commands.
+ # * +login+: Whether to simulate a login (set secondary groups, primary group, environment
+ # variables etc) as done by the OS in an actual login
# === Examples:
# Invoke find(1) to search for .rb files:
# find = Mixlib::ShellOut.new("find . -name '*.rb'")
@@ -192,6 +199,7 @@ module Mixlib
# The uid that the subprocess will switch to. If the user attribute was
# given as a username, it is converted to a uid by Etc.getpwnam
+ # TODO migrate to shellout/unix.rb
def uid
return nil unless user
user.kind_of?(Integer) ? user : Etc.getpwnam(user.to_s).uid
@@ -199,9 +207,11 @@ module Mixlib
# The gid that the subprocess will switch to. If the group attribute is
# given as a group name, it is converted to a gid by Etc.getgrnam
+ # TODO migrate to shellout/unix.rb
def gid
- return nil unless group
- group.kind_of?(Integer) ? group : Etc.getgrnam(group.to_s).gid
+ return group.kind_of?(Integer) ? group : Etc.getgrnam(group.to_s).gid if group
+ return Etc.getpwuid(uid).gid if using_login?
+ return nil
end
def timeout
@@ -322,7 +332,8 @@ module Mixlib
self.log_tag = setting
when 'environment', 'env'
self.environment = setting || {}
-
+ when 'login'
+ self.login = setting
else
raise InvalidCommandOption, "option '#{option.inspect}' is not a valid option for #{self.class.name}"
end
@@ -332,6 +343,9 @@ module Mixlib
end
def validate_options(opts)
+ if login && !user
+ raise InvalidCommandOption, "cannot set login without specifying a user"
+ end
super
end
end