diff options
author | Moser, Kevin <Kevin.Moser@nordstrom.com> | 2013-01-11 12:34:21 -0800 |
---|---|---|
committer | Moser, Kevin <Kevin.Moser@nordstrom.com> | 2013-01-11 12:34:21 -0800 |
commit | 493218537a11ecf1686741acb8c087bbfa27292d (patch) | |
tree | 4826d869d0191f48a5033842b9407b09e27174e3 | |
parent | d9124ef9fa7e798b329b1dcfb86bcb6ef48f452b (diff) | |
download | mixlib-shellout-493218537a11ecf1686741acb8c087bbfa27292d.tar.gz |
Add local_system file
-rw-r--r-- | lib/mixlib/shellout/windows.rb | 2 | ||||
-rw-r--r-- | lib/mixlib/shellout/windows/local_system.rb | 72 |
2 files changed, 73 insertions, 1 deletions
diff --git a/lib/mixlib/shellout/windows.rb b/lib/mixlib/shellout/windows.rb index a8511ef..4d9c87c 100644 --- a/lib/mixlib/shellout/windows.rb +++ b/lib/mixlib/shellout/windows.rb @@ -23,7 +23,7 @@ require 'windows/handle' require 'windows/process' require 'windows/synchronize' -require 'mixlib/shellout/windows/localsystem' +require 'mixlib/shellout/windows/local_system' require 'mixlib/shellout/windows/core_ext' module Mixlib diff --git a/lib/mixlib/shellout/windows/local_system.rb b/lib/mixlib/shellout/windows/local_system.rb new file mode 100644 index 0000000..ec88ab9 --- /dev/null +++ b/lib/mixlib/shellout/windows/local_system.rb @@ -0,0 +1,72 @@ +#-- +# Author:: Kevin Moser (<kevin.moser@nordstrom.com>) +# Copyright:: Copyright (c) 2012, 2013 Nordstrom, Inc. +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +require 'win32/process' +require 'windows/handle' +require 'windows/process' +require 'windows/synchronize' + +# Add new constants for Logon +module Process::Constants + LOGON32_LOGON_INTERACTIVE = 0x00000002 + LOGON32_PROVIDER_DEFAULT = 0x00000000 + + SID_MAX_SUB_AUTHORITIES = 0x00000015 + SECURITY_NT_AUTHORITY = 0x00000005 + SECURITY_LOCAL_SYSTEM_RID = 0x00000012 +end + +# Define the LogonUser function +module Process::Functions + module FFI::Library + # Wrapper method for attach_function + private + def attach_pfunc(*args) + attach_function(*args) + private args[0] + end + end + + extend FFI::Library + + ffi_lib :advapi32 + + attach_pfunc :LogonUser, :LogonUserA, + [:buffer_in, :buffer_in, :buffer_in, :ulong, :ulong, :pointer], :bool + + attach_pfunc :AllocateAndInitializeSid, + [:pointer, :uint, :ulong, :ulong, :ulong, :ulong, :ulong, :ulong, :ulong, :ulong, :pointer], :bool + attach_pfunc :EqualSid, [:pointer, :pointer], :bool + attach_pfunc :FreeSid, [:pointer], :pointer +end + +module Process + def is_local_system? + token = FFI::MemoryPointer.new(:ulong) + + unless OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, token) + raise SystemCallError, FFI.errno, "OpenProcessToken" + end + + puts("-------------------token pointer: #{token.read_ulong}") + + CloseHandle(token) + + end + + module_function :is_local_system? +end |