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

GetSecurityInfo

関数
ハンドルで指定したオブジェクトのセキュリティ情報を取得する。
DLLADVAPI32.dll呼出規約winapi対応OSWindows XP 以降

シグネチャ

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

WIN32_ERROR GetSecurityInfo(
    HANDLE handle,
    SE_OBJECT_TYPE ObjectType,
    OBJECT_SECURITY_INFORMATION SecurityInfo,
    PSID* ppsidOwner,   // optional
    PSID* ppsidGroup,   // optional
    ACL** ppDacl,   // optional
    ACL** ppSacl,   // optional
    PSECURITY_DESCRIPTOR* ppSecurityDescriptor   // optional
);

パラメーター

名前方向
handleHANDLEin
ObjectTypeSE_OBJECT_TYPEin
SecurityInfoOBJECT_SECURITY_INFORMATIONin
ppsidOwnerPSID*outoptional
ppsidGroupPSID*outoptional
ppDaclACL**outoptional
ppSaclACL**outoptional
ppSecurityDescriptorPSECURITY_DESCRIPTOR*outoptional

戻り値の型: WIN32_ERROR

各言語での呼び出し定義

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

WIN32_ERROR GetSecurityInfo(
    HANDLE handle,
    SE_OBJECT_TYPE ObjectType,
    OBJECT_SECURITY_INFORMATION SecurityInfo,
    PSID* ppsidOwner,   // optional
    PSID* ppsidGroup,   // optional
    ACL** ppDacl,   // optional
    ACL** ppSacl,   // optional
    PSECURITY_DESCRIPTOR* ppSecurityDescriptor   // optional
);
[DllImport("ADVAPI32.dll", ExactSpelling = true)]
static extern uint GetSecurityInfo(
    IntPtr handle,   // HANDLE
    int ObjectType,   // SE_OBJECT_TYPE
    uint SecurityInfo,   // OBJECT_SECURITY_INFORMATION
    IntPtr ppsidOwner,   // PSID* optional, out
    IntPtr ppsidGroup,   // PSID* optional, out
    IntPtr ppDacl,   // ACL** optional, out
    IntPtr ppSacl,   // ACL** optional, out
    IntPtr ppSecurityDescriptor   // PSECURITY_DESCRIPTOR* optional, out
);
<DllImport("ADVAPI32.dll", ExactSpelling:=True)>
Public Shared Function GetSecurityInfo(
    handle As IntPtr,   ' HANDLE
    ObjectType As Integer,   ' SE_OBJECT_TYPE
    SecurityInfo As UInteger,   ' OBJECT_SECURITY_INFORMATION
    ppsidOwner As IntPtr,   ' PSID* optional, out
    ppsidGroup As IntPtr,   ' PSID* optional, out
    ppDacl As IntPtr,   ' ACL** optional, out
    ppSacl As IntPtr,   ' ACL** optional, out
    ppSecurityDescriptor As IntPtr   ' PSECURITY_DESCRIPTOR* optional, out
) As UInteger
End Function
' handle : HANDLE
' ObjectType : SE_OBJECT_TYPE
' SecurityInfo : OBJECT_SECURITY_INFORMATION
' ppsidOwner : PSID* optional, out
' ppsidGroup : PSID* optional, out
' ppDacl : ACL** optional, out
' ppSacl : ACL** optional, out
' ppSecurityDescriptor : PSECURITY_DESCRIPTOR* optional, out
Declare PtrSafe Function GetSecurityInfo Lib "advapi32" ( _
    ByVal handle As LongPtr, _
    ByVal ObjectType As Long, _
    ByVal SecurityInfo As Long, _
    ByVal ppsidOwner As LongPtr, _
    ByVal ppsidGroup As LongPtr, _
    ByVal ppDacl As LongPtr, _
    ByVal ppSacl As LongPtr, _
    ByVal ppSecurityDescriptor As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

GetSecurityInfo = ctypes.windll.advapi32.GetSecurityInfo
GetSecurityInfo.restype = wintypes.DWORD
GetSecurityInfo.argtypes = [
    wintypes.HANDLE,  # handle : HANDLE
    ctypes.c_int,  # ObjectType : SE_OBJECT_TYPE
    wintypes.DWORD,  # SecurityInfo : OBJECT_SECURITY_INFORMATION
    ctypes.c_void_p,  # ppsidOwner : PSID* optional, out
    ctypes.c_void_p,  # ppsidGroup : PSID* optional, out
    ctypes.c_void_p,  # ppDacl : ACL** optional, out
    ctypes.c_void_p,  # ppSacl : ACL** optional, out
    ctypes.c_void_p,  # ppSecurityDescriptor : PSECURITY_DESCRIPTOR* optional, out
]
require 'fiddle'
require 'fiddle/import'

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

var (
	advapi32 = windows.NewLazySystemDLL("ADVAPI32.dll")
	procGetSecurityInfo = advapi32.NewProc("GetSecurityInfo")
)

// handle (HANDLE), ObjectType (SE_OBJECT_TYPE), SecurityInfo (OBJECT_SECURITY_INFORMATION), ppsidOwner (PSID* optional, out), ppsidGroup (PSID* optional, out), ppDacl (ACL** optional, out), ppSacl (ACL** optional, out), ppSecurityDescriptor (PSECURITY_DESCRIPTOR* optional, out)
r1, _, err := procGetSecurityInfo.Call(
	uintptr(handle),
	uintptr(ObjectType),
	uintptr(SecurityInfo),
	uintptr(ppsidOwner),
	uintptr(ppsidGroup),
	uintptr(ppDacl),
	uintptr(ppSacl),
	uintptr(ppSecurityDescriptor),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // WIN32_ERROR
function GetSecurityInfo(
  handle: THandle;   // HANDLE
  ObjectType: Integer;   // SE_OBJECT_TYPE
  SecurityInfo: DWORD;   // OBJECT_SECURITY_INFORMATION
  ppsidOwner: Pointer;   // PSID* optional, out
  ppsidGroup: Pointer;   // PSID* optional, out
  ppDacl: Pointer;   // ACL** optional, out
  ppSacl: Pointer;   // ACL** optional, out
  ppSecurityDescriptor: Pointer   // PSECURITY_DESCRIPTOR* optional, out
): DWORD; stdcall;
  external 'ADVAPI32.dll' name 'GetSecurityInfo';
result := DllCall("ADVAPI32\GetSecurityInfo"
    , "Ptr", handle   ; HANDLE
    , "Int", ObjectType   ; SE_OBJECT_TYPE
    , "UInt", SecurityInfo   ; OBJECT_SECURITY_INFORMATION
    , "Ptr", ppsidOwner   ; PSID* optional, out
    , "Ptr", ppsidGroup   ; PSID* optional, out
    , "Ptr", ppDacl   ; ACL** optional, out
    , "Ptr", ppSacl   ; ACL** optional, out
    , "Ptr", ppSecurityDescriptor   ; PSECURITY_DESCRIPTOR* optional, out
    , "UInt")   ; return: WIN32_ERROR
●GetSecurityInfo(handle, ObjectType, SecurityInfo, ppsidOwner, ppsidGroup, ppDacl, ppSacl, ppSecurityDescriptor) = DLL("ADVAPI32.dll", "dword GetSecurityInfo(void*, int, dword, void*, void*, void*, void*, void*)")
# 呼び出し: GetSecurityInfo(handle, ObjectType, SecurityInfo, ppsidOwner, ppsidGroup, ppDacl, ppSacl, ppSecurityDescriptor)
# handle : HANDLE -> "void*"
# ObjectType : SE_OBJECT_TYPE -> "int"
# SecurityInfo : OBJECT_SECURITY_INFORMATION -> "dword"
# ppsidOwner : PSID* optional, out -> "void*"
# ppsidGroup : PSID* optional, out -> "void*"
# ppDacl : ACL** optional, out -> "void*"
# ppSacl : ACL** optional, out -> "void*"
# ppSecurityDescriptor : PSECURITY_DESCRIPTOR* optional, out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。