summaryrefslogtreecommitdiff
path: root/lib/chef
diff options
context:
space:
mode:
authornimisha <nimisha.sharad@msystechnologies.com>2017-02-23 19:18:19 +0530
committerBryan McLellan <btm@loftninjas.org>2017-09-05 20:09:30 -0400
commit35f4cafac60770b59853d7e12b418f1971d234db (patch)
treeeb7278490f1cae24b74558477e7fe57248f138be /lib/chef
parent16ebc075e6214da2ad482bf9ffa74a4d5ae80b12 (diff)
downloadchef-35f4cafac60770b59853d7e12b418f1971d234db.tar.gz
Added define_resource_requirement and some other validations
Signed-off-by: nimisha <nimisha.sharad@msystechnologies.com>
Diffstat (limited to 'lib/chef')
-rw-r--r--lib/chef/mixin/user_context.rb4
-rw-r--r--lib/chef/provider/remote_file.rb17
-rw-r--r--lib/chef/provider/remote_file/fetcher.rb3
-rw-r--r--lib/chef/util/windows/logon_session.rb6
4 files changed, 27 insertions, 3 deletions
diff --git a/lib/chef/mixin/user_context.rb b/lib/chef/mixin/user_context.rb
index dfce6649bb..a8f7c4bd9c 100644
--- a/lib/chef/mixin/user_context.rb
+++ b/lib/chef/mixin/user_context.rb
@@ -23,6 +23,10 @@ class Chef
module UserContext
def with_user_context(user, password, domain = nil, &block)
+ if node["platform_family"] != "windows"
+ raise Exceptions::UnsupportedPlatform, "User context impersonation is supported only on the Windows platform"
+ end
+
if ! block_given?
raise ArgumentError, "You must supply a block to `with_user_context`"
end
diff --git a/lib/chef/provider/remote_file.rb b/lib/chef/provider/remote_file.rb
index c0a0f9433c..c692984bc0 100644
--- a/lib/chef/provider/remote_file.rb
+++ b/lib/chef/provider/remote_file.rb
@@ -29,6 +29,23 @@ class Chef
super
end
+ def define_resource_requirements
+ [ new_resource.remote_user, new_resource.remote_domain,
+ new_resource.remote_password ].each do |prop|
+ requirements.assert(:all_actions) do |a|
+ a.assertion do
+ if prop
+ node[:platform_family] == "windows"
+ else
+ true
+ end
+ end
+ a.failure_message Chef::Exceptions::UnsupportedPlatform, "'remote_user', 'remote_domain' and 'remote_password' properties are supported only for Windows platform"
+ a.whyrun("Assuming that the platform is Windows while passing 'remote_user', 'remote_domain' and 'remote_password' properties")
+ end
+ end
+ end
+
def load_current_resource
@current_resource = Chef::Resource::RemoteFile.new(new_resource.name)
super
diff --git a/lib/chef/provider/remote_file/fetcher.rb b/lib/chef/provider/remote_file/fetcher.rb
index 563d135d6a..6a4711d097 100644
--- a/lib/chef/provider/remote_file/fetcher.rb
+++ b/lib/chef/provider/remote_file/fetcher.rb
@@ -24,6 +24,9 @@ class Chef
def self.for_resource(uri, new_resource, current_resource)
if network_share?(uri)
+ if !Chef::Platform.windows?
+ raise Exceptions::UnsupportedPlatform, "Fetching the file on a network share is supported only on the Windows platform. Please change your source: #{uri}"
+ end
Chef::Provider::RemoteFile::NetworkFile.new(uri, new_resource, current_resource)
else
case uri.scheme
diff --git a/lib/chef/util/windows/logon_session.rb b/lib/chef/util/windows/logon_session.rb
index cf0a8000ef..6ef49e96a3 100644
--- a/lib/chef/util/windows/logon_session.rb
+++ b/lib/chef/util/windows/logon_session.rb
@@ -49,7 +49,7 @@ class Chef
status = Chef::ReservedNames::Win32::API::Security.LogonUserW(username, domain, password, Chef::ReservedNames::Win32::API::Security::LOGON32_LOGON_NETWORK, Chef::ReservedNames::Win32::API::Security::LOGON32_PROVIDER_DEFAULT, token)
- if status == 0
+ if !status
last_error = FFI::LastError.error
raise Chef::Exceptions::Win32APIError, "Logon for user `#{original_username}` failed with Win32 status #{last_error}."
end
@@ -82,7 +82,7 @@ class Chef
status = Chef::ReservedNames::Win32::API::Security.ImpersonateLoggedOnUser(token.read_ulong)
- if status == 0
+ if !status
last_error = FFI::LastError.error
raise Chef::Exceptions::Win32APIError, "Attempt to impersonate user `#{original_username}` failed with Win32 status #{last_error}."
end
@@ -96,7 +96,7 @@ class Chef
if impersonating
status = Chef::ReservedNames::Win32::API::Security.RevertToSelf
- if status == 0
+ if !status
last_error = FFI::LastError.error
raise Chef::Exceptions::Win32APIError, "Unable to restore user context with Win32 status #{last_error}."
end