summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/chef/win32/api/security.rb1
-rw-r--r--lib/chef/win32/security/token.rb8
2 files changed, 9 insertions, 0 deletions
diff --git a/lib/chef/win32/api/security.rb b/lib/chef/win32/api/security.rb
index cd6c409f17..a813c36bdd 100644
--- a/lib/chef/win32/api/security.rb
+++ b/lib/chef/win32/api/security.rb
@@ -357,6 +357,7 @@ class Chef
safe_attach_function :ConvertSidToStringSidA, [ :pointer, :pointer ], :BOOL
safe_attach_function :ConvertStringSidToSidW, [ :pointer, :pointer ], :BOOL
safe_attach_function :DeleteAce, [ :pointer, :DWORD ], :BOOL
+ safe_attach_function :DuplicateToken, [:HANDLE, :SECURITY_IMPERSONATION_LEVEL, :PHANDLE], :BOOL
safe_attach_function :EqualSid, [ :pointer, :pointer ], :BOOL
safe_attach_function :FreeSid, [ :pointer ], :pointer
safe_attach_function :GetAce, [ :pointer, :DWORD, :pointer ], :BOOL
diff --git a/lib/chef/win32/security/token.rb b/lib/chef/win32/security/token.rb
index ded4fc080e..9e494a73b9 100644
--- a/lib/chef/win32/security/token.rb
+++ b/lib/chef/win32/security/token.rb
@@ -58,6 +58,14 @@ class Chef
Chef::ReservedNames::Win32::Security::adjust_token_privileges(self, privileges_struct)
end
end
+
+ def duplicate_token(security_impersonation_level)
+ duplicate_token_handle = FFI::Buffer.new(:ulong)
+ unless Chef::ReservedNames::Win32::API::Security.DuplicateToken(handle.handle, security_impersonation_level, duplicate_token_handle)
+ raise Chef::ReservedNames::Win32::Error.raise!
+ end
+ Token.new(Handle.new(duplicate_token_handle.read_ulong))
+ end
end
end
end