diff options
author | Dan Sedlacek <svmastersamurai@users.noreply.github.com> | 2017-08-08 08:35:38 -0700 |
---|---|---|
committer | Bryan McLellan <btm@loftninjas.org> | 2017-08-08 11:35:38 -0400 |
commit | 35458abec91b644eb56b5bd38dd413391c069b63 (patch) | |
tree | 05d7bff646ca1baa9abad7cd0ec4d9c6b94c1312 /lib/chef/win32 | |
parent | 3d56d89f7ce5f8e3279e7e86ab215d4941fa70c0 (diff) | |
download | chef-35458abec91b644eb56b5bd38dd413391c069b63.tar.gz |
add option to enable unprivileged symlink creation on windows (#6236)
* add option to pass unprivileged symlink creation on windows
* redo check to be everytime depending on OS type and build
Signed-off-by: Daniel Sedlacek <dansedlacek@fb.com>
Diffstat (limited to 'lib/chef/win32')
-rw-r--r-- | lib/chef/win32/api/file.rb | 1 | ||||
-rw-r--r-- | lib/chef/win32/file.rb | 2 | ||||
-rw-r--r-- | lib/chef/win32/version.rb | 6 |
3 files changed, 9 insertions, 0 deletions
diff --git a/lib/chef/win32/api/file.rb b/lib/chef/win32/api/file.rb index 355cc81378..6aa2927e1f 100644 --- a/lib/chef/win32/api/file.rb +++ b/lib/chef/win32/api/file.rb @@ -67,6 +67,7 @@ class Chef MAX_PATH = 260 SYMBOLIC_LINK_FLAG_DIRECTORY = 0x1 + SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE = 0x2 FILE_NAME_NORMALIZED = 0x0 FILE_NAME_OPENED = 0x8 diff --git a/lib/chef/win32/file.rb b/lib/chef/win32/file.rb index fa3d0f7a9d..03d4496fa8 100644 --- a/lib/chef/win32/file.rb +++ b/lib/chef/win32/file.rb @@ -22,6 +22,7 @@ require "chef/win32/api/file" require "chef/win32/api/security" require "chef/win32/error" require "chef/win32/unicode" +require "chef/win32/version" class Chef module ReservedNames::Win32 @@ -60,6 +61,7 @@ class Chef # TODO do a check for CreateSymbolicLinkW and # raise NotImplemented exception on older Windows flags = ::File.directory?(old_name) ? SYMBOLIC_LINK_FLAG_DIRECTORY : 0 + flags |= SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE if Chef::ReservedNames::Win32::Version.new.win_10_creators_or_higher? old_name = encode_path(old_name) new_name = encode_path(new_name) unless CreateSymbolicLinkW(new_name, old_name, flags) diff --git a/lib/chef/win32/version.rb b/lib/chef/win32/version.rb index 3e2d6bc1fe..f8228d40b3 100644 --- a/lib/chef/win32/version.rb +++ b/lib/chef/win32/version.rb @@ -30,6 +30,8 @@ class Chef include Chef::ReservedNames::Win32::API::Macros include Chef::ReservedNames::Win32::API::System + attr_reader :major_version, :minor_version, :build_number + # Ruby implementation of # http://msdn.microsoft.com/en-us/library/ms724833(v=vs.85).aspx # http://msdn.microsoft.com/en-us/library/ms724358(v=vs.85).aspx @@ -114,6 +116,10 @@ class Chef end end + def win_10_creators_or_higher? + windows_10? && build_number >= 15063 + end + private def get_version |