Win32 API 日本語リファレンス
ホームSecurity › GetKernelObjectSecurity

GetKernelObjectSecurity

関数
カーネルオブジェクトのセキュリティ記述子を取得する。
DLLADVAPI32.dll呼出規約winapiSetLastErrorあり対応OSWindows XP 以降

シグネチャ

// ADVAPI32.dll
#include <windows.h>

BOOL GetKernelObjectSecurity(
    HANDLE Handle,
    DWORD RequestedInformation,
    PSECURITY_DESCRIPTOR pSecurityDescriptor,   // optional
    DWORD nLength,
    DWORD* lpnLengthNeeded
);

パラメーター

名前方向
HandleHANDLEin
RequestedInformationDWORDin
pSecurityDescriptorPSECURITY_DESCRIPTORoutoptional
nLengthDWORDin
lpnLengthNeededDWORD*out

戻り値の型: BOOL

各言語での呼び出し定義

// ADVAPI32.dll
#include <windows.h>

BOOL GetKernelObjectSecurity(
    HANDLE Handle,
    DWORD RequestedInformation,
    PSECURITY_DESCRIPTOR pSecurityDescriptor,   // optional
    DWORD nLength,
    DWORD* lpnLengthNeeded
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("ADVAPI32.dll", SetLastError = true, ExactSpelling = true)]
static extern bool GetKernelObjectSecurity(
    IntPtr Handle,   // HANDLE
    uint RequestedInformation,   // DWORD
    IntPtr pSecurityDescriptor,   // PSECURITY_DESCRIPTOR optional, out
    uint nLength,   // DWORD
    out uint lpnLengthNeeded   // DWORD* out
);
<DllImport("ADVAPI32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function GetKernelObjectSecurity(
    Handle As IntPtr,   ' HANDLE
    RequestedInformation As UInteger,   ' DWORD
    pSecurityDescriptor As IntPtr,   ' PSECURITY_DESCRIPTOR optional, out
    nLength As UInteger,   ' DWORD
    <Out> ByRef lpnLengthNeeded As UInteger   ' DWORD* out
) As Boolean
End Function
' Handle : HANDLE
' RequestedInformation : DWORD
' pSecurityDescriptor : PSECURITY_DESCRIPTOR optional, out
' nLength : DWORD
' lpnLengthNeeded : DWORD* out
Declare PtrSafe Function GetKernelObjectSecurity Lib "advapi32" ( _
    ByVal Handle As LongPtr, _
    ByVal RequestedInformation As Long, _
    ByVal pSecurityDescriptor As LongPtr, _
    ByVal nLength As Long, _
    ByRef lpnLengthNeeded As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

GetKernelObjectSecurity = ctypes.windll.advapi32.GetKernelObjectSecurity
GetKernelObjectSecurity.restype = wintypes.BOOL
GetKernelObjectSecurity.argtypes = [
    wintypes.HANDLE,  # Handle : HANDLE
    wintypes.DWORD,  # RequestedInformation : DWORD
    wintypes.HANDLE,  # pSecurityDescriptor : PSECURITY_DESCRIPTOR optional, out
    wintypes.DWORD,  # nLength : DWORD
    ctypes.POINTER(wintypes.DWORD),  # lpnLengthNeeded : DWORD* out
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('ADVAPI32.dll')
GetKernelObjectSecurity = Fiddle::Function.new(
  lib['GetKernelObjectSecurity'],
  [
    Fiddle::TYPE_VOIDP,  # Handle : HANDLE
    -Fiddle::TYPE_INT,  # RequestedInformation : DWORD
    Fiddle::TYPE_VOIDP,  # pSecurityDescriptor : PSECURITY_DESCRIPTOR optional, out
    -Fiddle::TYPE_INT,  # nLength : DWORD
    Fiddle::TYPE_VOIDP,  # lpnLengthNeeded : DWORD* out
  ],
  Fiddle::TYPE_INT)
#[link(name = "advapi32")]
extern "system" {
    fn GetKernelObjectSecurity(
        Handle: *mut core::ffi::c_void,  // HANDLE
        RequestedInformation: u32,  // DWORD
        pSecurityDescriptor: *mut core::ffi::c_void,  // PSECURITY_DESCRIPTOR optional, out
        nLength: u32,  // DWORD
        lpnLengthNeeded: *mut u32  // DWORD* out
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("ADVAPI32.dll", SetLastError = true)]
public static extern bool GetKernelObjectSecurity(IntPtr Handle, uint RequestedInformation, IntPtr pSecurityDescriptor, uint nLength, out uint lpnLengthNeeded);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ADVAPI32_GetKernelObjectSecurity' -Namespace Win32 -PassThru
# $api::GetKernelObjectSecurity(Handle, RequestedInformation, pSecurityDescriptor, nLength, lpnLengthNeeded)
#uselib "ADVAPI32.dll"
#func global GetKernelObjectSecurity "GetKernelObjectSecurity" sptr, sptr, sptr, sptr, sptr
; GetKernelObjectSecurity Handle, RequestedInformation, pSecurityDescriptor, nLength, varptr(lpnLengthNeeded)   ; 戻り値は stat
; Handle : HANDLE -> "sptr"
; RequestedInformation : DWORD -> "sptr"
; pSecurityDescriptor : PSECURITY_DESCRIPTOR optional, out -> "sptr"
; nLength : DWORD -> "sptr"
; lpnLengthNeeded : DWORD* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "ADVAPI32.dll"
#cfunc global GetKernelObjectSecurity "GetKernelObjectSecurity" sptr, int, sptr, int, var
; res = GetKernelObjectSecurity(Handle, RequestedInformation, pSecurityDescriptor, nLength, lpnLengthNeeded)
; Handle : HANDLE -> "sptr"
; RequestedInformation : DWORD -> "int"
; pSecurityDescriptor : PSECURITY_DESCRIPTOR optional, out -> "sptr"
; nLength : DWORD -> "int"
; lpnLengthNeeded : DWORD* out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; BOOL GetKernelObjectSecurity(HANDLE Handle, DWORD RequestedInformation, PSECURITY_DESCRIPTOR pSecurityDescriptor, DWORD nLength, DWORD* lpnLengthNeeded)
#uselib "ADVAPI32.dll"
#cfunc global GetKernelObjectSecurity "GetKernelObjectSecurity" intptr, int, intptr, int, var
; res = GetKernelObjectSecurity(Handle, RequestedInformation, pSecurityDescriptor, nLength, lpnLengthNeeded)
; Handle : HANDLE -> "intptr"
; RequestedInformation : DWORD -> "int"
; pSecurityDescriptor : PSECURITY_DESCRIPTOR optional, out -> "intptr"
; nLength : DWORD -> "int"
; lpnLengthNeeded : DWORD* out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	advapi32 = windows.NewLazySystemDLL("ADVAPI32.dll")
	procGetKernelObjectSecurity = advapi32.NewProc("GetKernelObjectSecurity")
)

// Handle (HANDLE), RequestedInformation (DWORD), pSecurityDescriptor (PSECURITY_DESCRIPTOR optional, out), nLength (DWORD), lpnLengthNeeded (DWORD* out)
r1, _, err := procGetKernelObjectSecurity.Call(
	uintptr(Handle),
	uintptr(RequestedInformation),
	uintptr(pSecurityDescriptor),
	uintptr(nLength),
	uintptr(lpnLengthNeeded),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function GetKernelObjectSecurity(
  Handle: THandle;   // HANDLE
  RequestedInformation: DWORD;   // DWORD
  pSecurityDescriptor: THandle;   // PSECURITY_DESCRIPTOR optional, out
  nLength: DWORD;   // DWORD
  lpnLengthNeeded: Pointer   // DWORD* out
): BOOL; stdcall;
  external 'ADVAPI32.dll' name 'GetKernelObjectSecurity';
result := DllCall("ADVAPI32\GetKernelObjectSecurity"
    , "Ptr", Handle   ; HANDLE
    , "UInt", RequestedInformation   ; DWORD
    , "Ptr", pSecurityDescriptor   ; PSECURITY_DESCRIPTOR optional, out
    , "UInt", nLength   ; DWORD
    , "Ptr", lpnLengthNeeded   ; DWORD* out
    , "Int")   ; return: BOOL
●GetKernelObjectSecurity(Handle, RequestedInformation, pSecurityDescriptor, nLength, lpnLengthNeeded) = DLL("ADVAPI32.dll", "bool GetKernelObjectSecurity(void*, dword, void*, dword, void*)")
# 呼び出し: GetKernelObjectSecurity(Handle, RequestedInformation, pSecurityDescriptor, nLength, lpnLengthNeeded)
# Handle : HANDLE -> "void*"
# RequestedInformation : DWORD -> "dword"
# pSecurityDescriptor : PSECURITY_DESCRIPTOR optional, out -> "void*"
# nLength : DWORD -> "dword"
# lpnLengthNeeded : DWORD* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。