Skip to content

Commit

Permalink
(PUP-838) Process uses LookupPrivilegeValueW
Browse files Browse the repository at this point in the history
 - Switch from LookupPrivilegeValueA to LookupPrivilegeValueW
 - In reality, this doesn't absolutely need to be done, but for the sake
   of consistency with other API calls, we use W suffixed functions
 - Add 2 tests that confirm that our usage of the Win32 API call is
   correct
  • Loading branch information
Iristyle committed May 24, 2014
1 parent 094b06c commit de9fcf8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
11 changes: 6 additions & 5 deletions lib/puppet/util/windows/process.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require 'ffi'

module Puppet::Util::Windows::Process
extend Puppet::Util::Windows::String
extend FFI::Library

WAIT_TIMEOUT = 0x102
Expand Down Expand Up @@ -57,9 +58,9 @@ def open_process_token(handle, desired_access)

def lookup_privilege_value(name, system_name = '')
luid = FFI::MemoryPointer.new(LUID.size)
result = LookupPrivilegeValueA(
system_name,
name.to_s,
result = LookupPrivilegeValueW(
wide_string(system_name),
wide_string(name.to_s),
luid
)

Expand Down Expand Up @@ -221,8 +222,8 @@ class LUID < FFI::Struct
# _Out_ PLUID lpLuid
# );
ffi_lib 'advapi32'
attach_function_private :LookupPrivilegeValueA,
[:lpcstr, :lpcstr, :pointer], :win32_bool
attach_function_private :LookupPrivilegeValueW,
[:lpcwstr, :lpcwstr, :pointer], :win32_bool

# http://msdn.microsoft.com/en-us/library/windows/desktop/aa379626(v=vs.85).aspx
TOKEN_INFORMATION_CLASS = enum(
Expand Down
11 changes: 11 additions & 0 deletions spec/integration/util/windows/process_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,16 @@
Puppet::Util::Windows::User.should be_admin
Puppet::Util::Windows::Process.process_privilege_symlink?.should be_false
end

it "should be able to lookup a standard Windows process privilege" do
luid = Puppet::Util::Windows::Process.lookup_privilege_value('SeShutdownPrivilege')
luid.should_not be_nil
luid.should be_instance_of(Puppet::Util::Windows::Process::LUID)
end

it "should raise an error for an unknown privilege name" do
fail_msg = /LookupPrivilegeValue\(, foo, .*\): A specified privilege does not exist/
expect { Puppet::Util::Windows::Process.lookup_privilege_value('foo') }.to raise_error(Puppet::Util::Windows::Error, fail_msg)
end
end
end

0 comments on commit de9fcf8

Please sign in to comment.