GetSecurityInfo
関数シグネチャ
// 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
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| handle | HANDLE | in | セキュリティ情報を取得する対象オブジェクトへのハンドルです。 |
| ObjectType | SE_OBJECT_TYPE | in | オブジェクトの種類を示す SE_OBJECT_TYPE 列挙値です。 |
| SecurityInfo | OBJECT_SECURITY_INFORMATION | in | 取得するセキュリティ情報の種類を示すビットフラグの集合です。このパラメーターには、 SECURITY_INFORMATION ビットフラグの組み合わせを指定できます。 |
| ppsidOwner | PSID* | outoptional | ppSecurityDescriptor で返されるセキュリティ記述子内の所有者 SID へのポインターを受け取る変数へのポインターです。返されるポインターは、OWNER_SECURITY_INFORMATION フラグを設定した場合にのみ有効です。所有者 SID が不要な場合、このパラメーターは NULL にできます。 |
| ppsidGroup | PSID* | outoptional | 返される セキュリティ記述子 内のプライマリグループ SID へのポインターを受け取る変数へのポインターです。返されるポインターは、GROUP_SECURITY_INFORMATION フラグを設定した場合にのみ有効です。グループ SID が不要な場合、このパラメーターは NULL にできます。 |
| ppDacl | ACL** | outoptional | 返されるセキュリティ記述子内の DACL へのポインターを受け取る変数へのポインターです。返されるポインターは、DACL_SECURITY_INFORMATION フラグを設定した場合にのみ有効です。DACL が不要な場合、このパラメーターは NULL にできます。 |
| ppSacl | ACL** | outoptional | 返されるセキュリティ記述子内の SACL へのポインターを受け取る変数へのポインターです。返されるポインターは、SACL_SECURITY_INFORMATION フラグを設定した場合にのみ有効です。SACL が不要な場合、このパラメーターは NULL にできます。 |
| ppSecurityDescriptor | PSECURITY_DESCRIPTOR* | outoptional | オブジェクトのセキュリティ記述子へのポインターを受け取る変数へのポインターです。ポインターの使用を終えたら、 LocalFree 関数を呼び出して、返されたバッファーを解放してください。 ppsidOwner、ppsidGroup、ppDacl、ppSacl のいずれかのパラメーターが NULL でない場合、このパラメーターは必須です。 |
戻り値の型: WIN32_ERROR
公式ドキュメント
ハンドルで指定されたオブジェクトのセキュリティ記述子のコピーを取得します。
戻り値
関数が成功した場合、戻り値は ERROR_SUCCESS です。
関数が失敗した場合、戻り値は WinError.h で定義されている 0 以外のエラーコードです。
解説(Remarks)
ppsidOwner、ppsidGroup、ppDacl、ppSacl の各パラメーターが NULL 以外であり、かつ SecurityInfo パラメーターでそれらをオブジェクトから取得するよう指定した場合、これらのパラメーターは ppSecurityDescriptor で返されるセキュリティ記述子内の対応する要素を指します。
オブジェクトのセキュリティ記述子から所有者、グループ、または DACL を読み取るには、ハンドルを開いた際に呼び出し側プロセスに READ_CONTROL アクセスが付与されている必要があります。READ_CONTROL アクセスを取得するには、呼び出し側がオブジェクトの所有者であるか、オブジェクトの DACL がそのアクセスを許可している必要があります。
セキュリティ記述子から SACL を読み取るには、ハンドルを開いた際に呼び出し側プロセスに ACCESS_SYSTEM_SECURITY アクセスが付与されている必要があります。このアクセスを取得する適切な方法は、呼び出し側の現在のトークンで SE_SECURITY_NAME 特権を有効にし、ACCESS_SYSTEM_SECURITY アクセスでハンドルを開いてから、特権を無効にすることです。特権を有効にすることによるセキュリティ上の影響については、Running with Special Privileges を参照してください。
GetSecurityInfo 関数は、次の種類のオブジェクトで使用できます。
- NTFS ファイルシステム上のローカルまたはリモートのファイルやディレクトリ
- 名前付きパイプ
- ローカルまたはリモートのプリンター
- ローカルまたはリモートの Windows サービス
- ネットワーク共有
- レジストリキー
- セマフォ、イベント、ミューテックス、待機可能タイマー
- プロセス、スレッド、ジョブ、ファイルマッピングオブジェクト
- 対話型サービスのウィンドウステーションおよびデスクトップ
- ディレクトリサービスオブジェクト
Examples
この関数を使用する例については、 Finding the Owner of a File Object を参照してください。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// 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 方式にも切替可。#uselib "ADVAPI32.dll" #cfunc global GetSecurityInfo "GetSecurityInfo" sptr, int, int, sptr, sptr, sptr, sptr, sptr ; res = GetSecurityInfo(handle, ObjectType, SecurityInfo, ppsidOwner, ppsidGroup, varptr(ppDacl), varptr(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 -> "sptr" ; ppSacl : ACL** optional, out -> "sptr" ; ppSecurityDescriptor : PSECURITY_DESCRIPTOR* optional, out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは 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 方式にも切替可。; 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, intptr, intptr, intptr ; res = GetSecurityInfo(handle, ObjectType, SecurityInfo, ppsidOwner, ppsidGroup, varptr(ppDacl), varptr(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 -> "intptr" ; ppSacl : ACL** optional, out -> "intptr" ; ppSecurityDescriptor : PSECURITY_DESCRIPTOR* optional, out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは 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_ERRORfunction 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)。const std = @import("std");
extern "advapi32" fn GetSecurityInfo(
handle: ?*anyopaque, // HANDLE
ObjectType: i32, // SE_OBJECT_TYPE
SecurityInfo: u32, // OBJECT_SECURITY_INFORMATION
ppsidOwner: ?*anyopaque, // PSID* optional, out
ppsidGroup: ?*anyopaque, // PSID* optional, out
ppDacl: [*c][*c]ACL, // ACL** optional, out
ppSacl: [*c][*c]ACL, // ACL** optional, out
ppSecurityDescriptor: ?*anyopaque // PSECURITY_DESCRIPTOR* optional, out
) callconv(std.os.windows.WINAPI) u32;proc GetSecurityInfo(
handle: pointer, # HANDLE
ObjectType: int32, # SE_OBJECT_TYPE
SecurityInfo: uint32, # OBJECT_SECURITY_INFORMATION
ppsidOwner: pointer, # PSID* optional, out
ppsidGroup: pointer, # PSID* optional, out
ppDacl: ptr ACL, # ACL** optional, out
ppSacl: ptr ACL, # ACL** optional, out
ppSecurityDescriptor: pointer # PSECURITY_DESCRIPTOR* optional, out
): uint32 {.importc: "GetSecurityInfo", stdcall, dynlib: "ADVAPI32.dll".}pragma(lib, "advapi32");
extern(Windows)
uint GetSecurityInfo(
void* handle, // HANDLE
int ObjectType, // SE_OBJECT_TYPE
uint SecurityInfo, // OBJECT_SECURITY_INFORMATION
void* ppsidOwner, // PSID* optional, out
void* ppsidGroup, // PSID* optional, out
ACL** ppDacl, // ACL** optional, out
ACL** ppSacl, // ACL** optional, out
void* ppSecurityDescriptor // PSECURITY_DESCRIPTOR* optional, out
);ccall((:GetSecurityInfo, "ADVAPI32.dll"), stdcall, UInt32,
(Ptr{Cvoid}, Int32, UInt32, Ptr{Cvoid}, Ptr{Cvoid}, Ptr{ACL}, Ptr{ACL}, Ptr{Cvoid}),
handle, ObjectType, SecurityInfo, ppsidOwner, ppsidGroup, ppDacl, ppSacl, ppSecurityDescriptor)
# handle : HANDLE -> Ptr{Cvoid}
# ObjectType : SE_OBJECT_TYPE -> Int32
# SecurityInfo : OBJECT_SECURITY_INFORMATION -> UInt32
# ppsidOwner : PSID* optional, out -> Ptr{Cvoid}
# ppsidGroup : PSID* optional, out -> Ptr{Cvoid}
# ppDacl : ACL** optional, out -> Ptr{ACL}
# ppSacl : ACL** optional, out -> Ptr{ACL}
# ppSecurityDescriptor : PSECURITY_DESCRIPTOR* optional, out -> Ptr{Cvoid}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
uint32_t GetSecurityInfo(
void* handle,
int32_t ObjectType,
uint32_t SecurityInfo,
void* ppsidOwner,
void* ppsidGroup,
void* ppDacl,
void* ppSacl,
void* ppSecurityDescriptor);
]]
local advapi32 = ffi.load("advapi32")
-- advapi32.GetSecurityInfo(handle, ObjectType, SecurityInfo, ppsidOwner, ppsidGroup, ppDacl, ppSacl, ppSecurityDescriptor)
-- 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
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('ADVAPI32.dll');
const GetSecurityInfo = lib.func('__stdcall', 'GetSecurityInfo', 'uint32_t', ['void *', 'int32_t', 'uint32_t', 'void *', 'void *', 'void *', 'void *', 'void *']);
// GetSecurityInfo(handle, ObjectType, SecurityInfo, ppsidOwner, ppsidGroup, ppDacl, ppSacl, ppSecurityDescriptor)
// handle : HANDLE -> 'void *'
// ObjectType : SE_OBJECT_TYPE -> 'int32_t'
// SecurityInfo : OBJECT_SECURITY_INFORMATION -> 'uint32_t'
// 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 *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("ADVAPI32.dll", {
GetSecurityInfo: { parameters: ["pointer", "i32", "u32", "pointer", "pointer", "pointer", "pointer", "pointer"], result: "u32" },
});
// lib.symbols.GetSecurityInfo(handle, ObjectType, SecurityInfo, ppsidOwner, ppsidGroup, ppDacl, ppSacl, ppSecurityDescriptor)
// handle : HANDLE -> "pointer"
// ObjectType : SE_OBJECT_TYPE -> "i32"
// SecurityInfo : OBJECT_SECURITY_INFORMATION -> "u32"
// ppsidOwner : PSID* optional, out -> "pointer"
// ppsidGroup : PSID* optional, out -> "pointer"
// ppDacl : ACL** optional, out -> "pointer"
// ppSacl : ACL** optional, out -> "pointer"
// ppSecurityDescriptor : PSECURITY_DESCRIPTOR* optional, out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
uint32_t GetSecurityInfo(
void* handle,
int32_t ObjectType,
uint32_t SecurityInfo,
void* ppsidOwner,
void* ppsidGroup,
void* ppDacl,
void* ppSacl,
void* ppSecurityDescriptor);
C, "ADVAPI32.dll");
// $ffi->GetSecurityInfo(handle, ObjectType, SecurityInfo, ppsidOwner, ppsidGroup, ppDacl, ppSacl, ppSecurityDescriptor);
// 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
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
// WINAPI(stdcall): x64 では呼出規約が統一されるため問題なし。x86 では __stdcall 対応のラッパが必要な場合あり。import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;
public interface Advapi32 extends StdCallLibrary {
Advapi32 INSTANCE = Native.load("advapi32", Advapi32.class);
int GetSecurityInfo(
Pointer handle, // HANDLE
int ObjectType, // SE_OBJECT_TYPE
int SecurityInfo, // OBJECT_SECURITY_INFORMATION
Pointer ppsidOwner, // PSID* optional, out
Pointer ppsidGroup, // PSID* optional, out
Pointer ppDacl, // ACL** optional, out
Pointer ppSacl, // ACL** optional, out
Pointer ppSecurityDescriptor // PSECURITY_DESCRIPTOR* optional, out
);
}@[Link("advapi32")]
lib LibADVAPI32
fun GetSecurityInfo = GetSecurityInfo(
handle : Void*, # HANDLE
ObjectType : Int32, # SE_OBJECT_TYPE
SecurityInfo : UInt32, # OBJECT_SECURITY_INFORMATION
ppsidOwner : Void*, # PSID* optional, out
ppsidGroup : Void*, # PSID* optional, out
ppDacl : ACL**, # ACL** optional, out
ppSacl : ACL**, # ACL** optional, out
ppSecurityDescriptor : Void* # PSECURITY_DESCRIPTOR* optional, out
) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef GetSecurityInfoNative = Uint32 Function(Pointer<Void>, Int32, Uint32, Pointer<Void>, Pointer<Void>, Pointer<Void>, Pointer<Void>, Pointer<Void>);
typedef GetSecurityInfoDart = int Function(Pointer<Void>, int, int, Pointer<Void>, Pointer<Void>, Pointer<Void>, Pointer<Void>, Pointer<Void>);
final GetSecurityInfo = DynamicLibrary.open('ADVAPI32.dll')
.lookupFunction<GetSecurityInfoNative, GetSecurityInfoDart>('GetSecurityInfo');
// handle : HANDLE -> Pointer<Void>
// ObjectType : SE_OBJECT_TYPE -> Int32
// SecurityInfo : OBJECT_SECURITY_INFORMATION -> Uint32
// ppsidOwner : PSID* optional, out -> Pointer<Void>
// ppsidGroup : PSID* optional, out -> Pointer<Void>
// ppDacl : ACL** optional, out -> Pointer<Void>
// ppSacl : ACL** optional, out -> Pointer<Void>
// ppSecurityDescriptor : PSECURITY_DESCRIPTOR* optional, out -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
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';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "GetSecurityInfo"
c_GetSecurityInfo :: Ptr () -> Int32 -> Word32 -> Ptr () -> Ptr () -> Ptr () -> Ptr () -> Ptr () -> IO Word32
-- handle : HANDLE -> Ptr ()
-- ObjectType : SE_OBJECT_TYPE -> Int32
-- SecurityInfo : OBJECT_SECURITY_INFORMATION -> Word32
-- 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 -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let getsecurityinfo =
foreign "GetSecurityInfo"
((ptr void) @-> int32_t @-> uint32_t @-> (ptr void) @-> (ptr void) @-> (ptr void) @-> (ptr void) @-> (ptr void) @-> returning uint32_t)
(* handle : HANDLE -> (ptr void) *)
(* ObjectType : SE_OBJECT_TYPE -> int32_t *)
(* SecurityInfo : OBJECT_SECURITY_INFORMATION -> uint32_t *)
(* ppsidOwner : PSID* optional, out -> (ptr void) *)
(* ppsidGroup : PSID* optional, out -> (ptr void) *)
(* ppDacl : ACL** optional, out -> (ptr void) *)
(* ppSacl : ACL** optional, out -> (ptr void) *)
(* ppSecurityDescriptor : PSECURITY_DESCRIPTOR* optional, out -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library advapi32 (t "ADVAPI32.dll"))
(cffi:use-foreign-library advapi32)
(cffi:defcfun ("GetSecurityInfo" get-security-info :convention :stdcall) :uint32
(handle :pointer) ; HANDLE
(object-type :int32) ; SE_OBJECT_TYPE
(security-info :uint32) ; OBJECT_SECURITY_INFORMATION
(ppsid-owner :pointer) ; PSID* optional, out
(ppsid-group :pointer) ; PSID* optional, out
(pp-dacl :pointer) ; ACL** optional, out
(pp-sacl :pointer) ; ACL** optional, out
(pp-security-descriptor :pointer)) ; PSECURITY_DESCRIPTOR* optional, out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $GetSecurityInfo = Win32::API::More->new('ADVAPI32',
'DWORD GetSecurityInfo(HANDLE handle, int ObjectType, DWORD SecurityInfo, HANDLE ppsidOwner, HANDLE ppsidGroup, LPVOID ppDacl, LPVOID ppSacl, HANDLE ppSecurityDescriptor)');
# my $ret = $GetSecurityInfo->Call($handle, $ObjectType, $SecurityInfo, $ppsidOwner, $ppsidGroup, $ppDacl, $ppSacl, $ppSecurityDescriptor);
# handle : HANDLE -> HANDLE
# ObjectType : SE_OBJECT_TYPE -> int
# SecurityInfo : OBJECT_SECURITY_INFORMATION -> DWORD
# ppsidOwner : PSID* optional, out -> HANDLE
# ppsidGroup : PSID* optional, out -> HANDLE
# ppDacl : ACL** optional, out -> LPVOID
# ppSacl : ACL** optional, out -> LPVOID
# ppSecurityDescriptor : PSECURITY_DESCRIPTOR* optional, out -> HANDLE
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
- f GetNamedSecurityInfoW — 名前付きオブジェクトのセキュリティ情報を取得する(Unicode版)。
- f LocalFree — ローカルメモリオブジェクトを解放する。
- s SECURITY_DESCRIPTOR
- s SID
- f SetNamedSecurityInfoW — 名前付きオブジェクトのセキュリティ情報を設定する(Unicode版)。
- f SetSecurityInfo — ハンドルで指定したオブジェクトのセキュリティ情報を設定する。