summaryrefslogtreecommitdiff
path: root/lib/chef/resource
diff options
context:
space:
mode:
authorNimesh <nimesh.patni@msystechnologies.com>2018-11-13 01:07:34 +0530
committerNimesh-Msys <nimesh.patni@msystechnologies.com>2019-01-07 14:33:58 +0530
commit560d568366f73c9915f64eb0f12f3421245e7cc1 (patch)
tree47c38379b1db6d964d1f2b35ad37e3a9fc741879 /lib/chef/resource
parent45d7d458bf74d3979b0b8ca2172996d6cba9aace (diff)
downloadchef-560d568366f73c9915f64eb0f12f3421245e7cc1.tar.gz
windows_task resource: allow non-system users without password for interactive tasks
- Minor changes in `validate_user_and_password` to support this feature - `validate_interactive_setting` would no longer be needed - Added test cases - Added support to latest version of win32-taskscheduler gem (2.0.4) - Fixes MSYS-924 Signed-off-by: Nimesh <nimesh.patni@msystechnologies.com>
Diffstat (limited to 'lib/chef/resource')
-rw-r--r--lib/chef/resource/windows_task.rb25
1 files changed, 17 insertions, 8 deletions
diff --git a/lib/chef/resource/windows_task.rb b/lib/chef/resource/windows_task.rb
index 5bd6d7e557..f664fc57be 100644
--- a/lib/chef/resource/windows_task.rb
+++ b/lib/chef/resource/windows_task.rb
@@ -143,7 +143,6 @@ class Chef
validate_start_time(start_time, frequency)
validate_start_day(start_day, frequency) if start_day
validate_user_and_password(user, password)
- validate_interactive_setting(interactive_enabled, password)
validate_create_frequency_modifier(frequency, frequency_modifier) if frequency_modifier
validate_create_day(day, frequency, frequency_modifier) if day
validate_create_months(months, frequency) if months
@@ -226,20 +225,30 @@ class Chef
end
end
+ # System users will not require a password
+ # Other users will require a password if the task is non-interactive.
+ #
+ # @param [String] user
+ # @param [String] password
+ #
def validate_user_and_password(user, password)
- if password_required?(user) && password.nil?
- raise ArgumentError, "Cannot specify a user other than the system users without specifying a password!. Valid passwordless users: '#{Chef::ReservedNames::Win32::Security::SID::SYSTEM_USER.join("', '")}'"
+ if non_system_user?(user)
+ if password.nil? && !interactive_enabled
+ raise ArgumentError, "Please provide a password or check if this task needs to be interactive! Valid passwordless users are: '#{Chef::ReservedNames::Win32::Security::SID::SYSTEM_USER.join("', '")}'"
+ end
+ else
+ unless password.nil?
+ raise ArgumentError, "Password is not required for system users."
+ end
end
end
+ # Password is not required for system user and required for non-system user.
def password_required?(user)
- return false if user.nil?
- @password_required ||= !Chef::ReservedNames::Win32::Security::SID.system_user?(user)
+ @password_required ||= (!user.nil? && !Chef::ReservedNames::Win32::Security::SID.system_user?(user))
end
- def validate_interactive_setting(interactive_enabled, password)
- raise ArgumentError, "Please provide the password when attempting to set interactive/non-interactive." if interactive_enabled && password.nil?
- end
+ alias non_system_user? password_required?
def validate_create_frequency_modifier(frequency, frequency_modifier)
if ([:on_logon, :onstart, :on_idle, :none].include?(frequency)) && ( frequency_modifier != 1)