GetNamedSecurityInfoW
関数シグネチャ
// ADVAPI32.dll (Unicode / -W)
#include <windows.h>
WIN32_ERROR GetNamedSecurityInfoW(
LPCWSTR pObjectName,
SE_OBJECT_TYPE ObjectType,
OBJECT_SECURITY_INFORMATION SecurityInfo,
PSID* ppsidOwner, // optional
PSID* ppsidGroup, // optional
ACL** ppDacl, // optional
ACL** ppSacl, // optional
PSECURITY_DESCRIPTOR* ppSecurityDescriptor
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| pObjectName | LPCWSTR | in | セキュリティ情報を取得する対象オブジェクトの名前を指定する、null で終わる文字列へのポインターです。各オブジェクト型における文字列形式の説明については、 SE_OBJECT_TYPE を参照してください。 |
| ObjectType | SE_OBJECT_TYPE | in | pObjectName パラメーターで指定されたオブジェクトの型を示す、SE_OBJECT_TYPE 列挙体の値を指定します。 |
| SecurityInfo | OBJECT_SECURITY_INFORMATION | in | 取得するセキュリティ情報の種類を示す ビットフラグのセットです。このパラメーターには、 SECURITY_INFORMATION ビットフラグの組み合わせを指定できます。 |
| ppsidOwner | PSID* | outoptional | ppSecurityDescriptor に返される セキュリティ記述子 内の所有者 SID へのポインターを受け取る変数へのポインターです。セキュリティ記述子に所有者 SID がない場合は NULL を受け取ります。返されるポインターは、OWNER_SECURITY_INFORMATION フラグを設定した場合にのみ有効です。また、所有者 SID が不要な場合、このパラメーターには NULL を指定できます。 |
| ppsidGroup | PSID* | outoptional | 返されたセキュリティ記述子内のプライマリグループ SID へのポインターを受け取る変数へのポインターです。セキュリティ記述子にグループ SID がない場合は NULL を受け取ります。返されるポインターは、GROUP_SECURITY_INFORMATION フラグを設定した場合にのみ有効です。また、グループ SID が不要な場合、このパラメーターには NULL を指定できます。 |
| ppDacl | ACL** | outoptional | 返されたセキュリティ記述子内の DACL へのポインターを受け取る変数へのポインターです。セキュリティ記述子に DACL がない場合は NULL を受け取ります。返されるポインターは、DACL_SECURITY_INFORMATION フラグを設定した場合にのみ有効です。また、DACL が不要な場合、このパラメーターには NULL を指定できます。 |
| ppSacl | ACL** | outoptional | 返されたセキュリティ記述子内の SACL へのポインターを受け取る変数へのポインターです。セキュリティ記述子に SACL がない場合は NULL を受け取ります。返されるポインターは、SACL_SECURITY_INFORMATION フラグを設定した場合にのみ有効です。また、SACL が不要な場合、このパラメーターには NULL を指定できます。 |
| ppSecurityDescriptor | PSECURITY_DESCRIPTOR* | out | オブジェクトのセキュリティ記述子へのポインターを受け取る変数へのポインターです。ポインターの使用が終わったら、 LocalFree 関数を呼び出して、返されたバッファーを解放してください。 このパラメーターは、ppsidOwner、ppsidGroup、ppDacl、ppSacl のいずれかのパラメーターが NULL 以外である場合に必須です。 |
戻り値の型: WIN32_ERROR
公式ドキュメント
名前で指定されたオブジェクトのセキュリティ記述子のコピーを取得します。(Unicode)
戻り値
関数が成功した場合、戻り値は ERROR_SUCCESS です。
関数が失敗した場合、戻り値は WinError.h で定義されている 0 以外のエラーコードです。
解説(Remarks)
ppsidOwner、ppsidGroup、ppDacl、ppSacl のいずれかのパラメーターが NULL 以外で、かつ SecurityInfo パラメーターでそれらをオブジェクトから取得するよう指定した場合、それらのパラメーターは ppSecurityDescriptor に返される セキュリティ記述子 内の対応する要素を指します。セキュリティ記述子に要求された情報が含まれていない場合、対応するパラメーターには NULL が設定されます。
オブジェクトのセキュリティ記述子から所有者、グループ、または DACL を読み取るには、オブジェクトの DACL が呼び出し元に READ_CONTROL アクセスを許可しているか、呼び出し元がオブジェクトの所有者である必要があります。
オブジェクトのシステムアクセス制御リスト (SACL) を読み取るには、呼び出し元のプロセスで SE_SECURITY_NAME 特権が有効になっている必要があります。特権を有効にすることのセキュリティ上の影響については、Running with Special Privileges を参照してください。
GetNamedSecurityInfo 関数は、次の種類のオブジェクトで使用できます。
- NTFS ファイルシステム上のローカルまたはリモートのファイルおよびディレクトリ
- ローカルまたはリモートのプリンター
- ローカルまたはリモートの Windows サービス
- ネットワーク共有
- レジストリキー
- セマフォ、イベント、ミューテックス、待機可能タイマー
- ファイルマッピングオブジェクト
- ディレクトリサービスオブジェクト
この関数は情報を平文 (plaintext) で転送します。システムで署名が無効化されていない限り、この関数が転送する情報には署名が施されますが、暗号化は行われません。
ユーザーアカウント、グループアカウント、またはログオンセッションを通じてオブジェクトへのアクセスを制御する方法の詳細については、How DACLs Control Access to an Object を参照してください。
使用例
GetNamedSecurityInfo を使用する例については、Modifying the ACLs of an Object を参照してください。
aclapi.h ヘッダーは、UNICODE プリプロセッサ定数の定義に応じて、この関数の ANSI 版または Unicode 版を自動的に選択するエイリアスとして GetNamedSecurityInfo を定義しています。エンコーディング中立のエイリアスと、エンコーディング中立でないコードを混在させて使用すると、不一致が生じ、コンパイルエラーや実行時エラーの原因となる場合があります。詳細については、Conventions for Function Prototypes を参照してください。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// ADVAPI32.dll (Unicode / -W)
#include <windows.h>
WIN32_ERROR GetNamedSecurityInfoW(
LPCWSTR pObjectName,
SE_OBJECT_TYPE ObjectType,
OBJECT_SECURITY_INFORMATION SecurityInfo,
PSID* ppsidOwner, // optional
PSID* ppsidGroup, // optional
ACL** ppDacl, // optional
ACL** ppSacl, // optional
PSECURITY_DESCRIPTOR* ppSecurityDescriptor
);[DllImport("ADVAPI32.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern uint GetNamedSecurityInfoW(
[MarshalAs(UnmanagedType.LPWStr)] string pObjectName, // LPCWSTR
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* out
);<DllImport("ADVAPI32.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function GetNamedSecurityInfoW(
<MarshalAs(UnmanagedType.LPWStr)> pObjectName As String, ' LPCWSTR
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* out
) As UInteger
End Function' pObjectName : LPCWSTR
' 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* out
Declare PtrSafe Function GetNamedSecurityInfoW Lib "advapi32" ( _
ByVal pObjectName 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
' Unicode(W): 文字列は ByVal As LongPtr とし StrPtr(unicodeStr) を渡す
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
GetNamedSecurityInfoW = ctypes.windll.advapi32.GetNamedSecurityInfoW
GetNamedSecurityInfoW.restype = wintypes.DWORD
GetNamedSecurityInfoW.argtypes = [
wintypes.LPCWSTR, # pObjectName : LPCWSTR
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* out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('ADVAPI32.dll')
GetNamedSecurityInfoW = Fiddle::Function.new(
lib['GetNamedSecurityInfoW'],
[
Fiddle::TYPE_VOIDP, # pObjectName : LPCWSTR
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* out
],
-Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "advapi32")]
extern "system" {
fn GetNamedSecurityInfoW(
pObjectName: *const u16, // LPCWSTR
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* out
) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("ADVAPI32.dll", CharSet = CharSet.Unicode)]
public static extern uint GetNamedSecurityInfoW([MarshalAs(UnmanagedType.LPWStr)] string pObjectName, int ObjectType, uint SecurityInfo, IntPtr ppsidOwner, IntPtr ppsidGroup, IntPtr ppDacl, IntPtr ppSacl, IntPtr ppSecurityDescriptor);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ADVAPI32_GetNamedSecurityInfoW' -Namespace Win32 -PassThru
# $api::GetNamedSecurityInfoW(pObjectName, ObjectType, SecurityInfo, ppsidOwner, ppsidGroup, ppDacl, ppSacl, ppSecurityDescriptor)#uselib "ADVAPI32.dll"
#func global GetNamedSecurityInfoW "GetNamedSecurityInfoW" wptr, wptr, wptr, wptr, wptr, wptr, wptr, wptr
; GetNamedSecurityInfoW pObjectName, ObjectType, SecurityInfo, ppsidOwner, ppsidGroup, varptr(ppDacl), varptr(ppSacl), ppSecurityDescriptor ; 戻り値は stat
; pObjectName : LPCWSTR -> "wptr"
; ObjectType : SE_OBJECT_TYPE -> "wptr"
; SecurityInfo : OBJECT_SECURITY_INFORMATION -> "wptr"
; ppsidOwner : PSID* optional, out -> "wptr"
; ppsidGroup : PSID* optional, out -> "wptr"
; ppDacl : ACL** optional, out -> "wptr"
; ppSacl : ACL** optional, out -> "wptr"
; ppSecurityDescriptor : PSECURITY_DESCRIPTOR* out -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "ADVAPI32.dll" #cfunc global GetNamedSecurityInfoW "GetNamedSecurityInfoW" wstr, int, int, sptr, sptr, var, var, sptr ; res = GetNamedSecurityInfoW(pObjectName, ObjectType, SecurityInfo, ppsidOwner, ppsidGroup, ppDacl, ppSacl, ppSecurityDescriptor) ; pObjectName : LPCWSTR -> "wstr" ; 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* out -> "sptr" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "ADVAPI32.dll" #cfunc global GetNamedSecurityInfoW "GetNamedSecurityInfoW" wstr, int, int, sptr, sptr, sptr, sptr, sptr ; res = GetNamedSecurityInfoW(pObjectName, ObjectType, SecurityInfo, ppsidOwner, ppsidGroup, varptr(ppDacl), varptr(ppSacl), ppSecurityDescriptor) ; pObjectName : LPCWSTR -> "wstr" ; 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* out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
; WIN32_ERROR GetNamedSecurityInfoW(LPCWSTR pObjectName, SE_OBJECT_TYPE ObjectType, OBJECT_SECURITY_INFORMATION SecurityInfo, PSID* ppsidOwner, PSID* ppsidGroup, ACL** ppDacl, ACL** ppSacl, PSECURITY_DESCRIPTOR* ppSecurityDescriptor) #uselib "ADVAPI32.dll" #cfunc global GetNamedSecurityInfoW "GetNamedSecurityInfoW" wstr, int, int, intptr, intptr, var, var, intptr ; res = GetNamedSecurityInfoW(pObjectName, ObjectType, SecurityInfo, ppsidOwner, ppsidGroup, ppDacl, ppSacl, ppSecurityDescriptor) ; pObjectName : LPCWSTR -> "wstr" ; 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* out -> "intptr" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; WIN32_ERROR GetNamedSecurityInfoW(LPCWSTR pObjectName, SE_OBJECT_TYPE ObjectType, OBJECT_SECURITY_INFORMATION SecurityInfo, PSID* ppsidOwner, PSID* ppsidGroup, ACL** ppDacl, ACL** ppSacl, PSECURITY_DESCRIPTOR* ppSecurityDescriptor) #uselib "ADVAPI32.dll" #cfunc global GetNamedSecurityInfoW "GetNamedSecurityInfoW" wstr, int, int, intptr, intptr, intptr, intptr, intptr ; res = GetNamedSecurityInfoW(pObjectName, ObjectType, SecurityInfo, ppsidOwner, ppsidGroup, varptr(ppDacl), varptr(ppSacl), ppSecurityDescriptor) ; pObjectName : LPCWSTR -> "wstr" ; 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* out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
advapi32 = windows.NewLazySystemDLL("ADVAPI32.dll")
procGetNamedSecurityInfoW = advapi32.NewProc("GetNamedSecurityInfoW")
)
// pObjectName (LPCWSTR), 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* out)
r1, _, err := procGetNamedSecurityInfoW.Call(
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pObjectName))),
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 GetNamedSecurityInfoW(
pObjectName: PWideChar; // LPCWSTR
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* out
): DWORD; stdcall;
external 'ADVAPI32.dll' name 'GetNamedSecurityInfoW';result := DllCall("ADVAPI32\GetNamedSecurityInfoW"
, "WStr", pObjectName ; LPCWSTR
, "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* out
, "UInt") ; return: WIN32_ERROR●GetNamedSecurityInfoW(pObjectName, ObjectType, SecurityInfo, ppsidOwner, ppsidGroup, ppDacl, ppSacl, ppSecurityDescriptor) = DLL("ADVAPI32.dll", "dword GetNamedSecurityInfoW(char*, int, dword, void*, void*, void*, void*, void*)")
# 呼び出し: GetNamedSecurityInfoW(pObjectName, ObjectType, SecurityInfo, ppsidOwner, ppsidGroup, ppDacl, ppSacl, ppSecurityDescriptor)
# pObjectName : LPCWSTR -> "char*"
# 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* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。const std = @import("std");
extern "advapi32" fn GetNamedSecurityInfoW(
pObjectName: [*c]const u16, // LPCWSTR
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* out
) callconv(std.os.windows.WINAPI) u32;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。proc GetNamedSecurityInfoW(
pObjectName: WideCString, # LPCWSTR
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* out
): uint32 {.importc: "GetNamedSecurityInfoW", stdcall, dynlib: "ADVAPI32.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。pragma(lib, "advapi32");
extern(Windows)
uint GetNamedSecurityInfoW(
const(wchar)* pObjectName, // LPCWSTR
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* out
);ccall((:GetNamedSecurityInfoW, "ADVAPI32.dll"), stdcall, UInt32,
(Cwstring, Int32, UInt32, Ptr{Cvoid}, Ptr{Cvoid}, Ptr{ACL}, Ptr{ACL}, Ptr{Cvoid}),
pObjectName, ObjectType, SecurityInfo, ppsidOwner, ppsidGroup, ppDacl, ppSacl, ppSecurityDescriptor)
# pObjectName : LPCWSTR -> Cwstring
# 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* out -> Ptr{Cvoid}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。local ffi = require("ffi")
ffi.cdef[[
uint32_t GetNamedSecurityInfoW(
const uint16_t* pObjectName,
int32_t ObjectType,
uint32_t SecurityInfo,
void* ppsidOwner,
void* ppsidGroup,
void* ppDacl,
void* ppSacl,
void* ppSecurityDescriptor);
]]
local advapi32 = ffi.load("advapi32")
-- advapi32.GetNamedSecurityInfoW(pObjectName, ObjectType, SecurityInfo, ppsidOwner, ppsidGroup, ppDacl, ppSacl, ppSecurityDescriptor)
-- pObjectName : LPCWSTR
-- 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* out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
-- Unicode(-W): uint16_t* には UTF-16LE のバッファ(ffi.new("uint16_t[?]", ...))を渡す。const koffi = require('koffi');
const lib = koffi.load('ADVAPI32.dll');
const GetNamedSecurityInfoW = lib.func('__stdcall', 'GetNamedSecurityInfoW', 'uint32_t', ['str16', 'int32_t', 'uint32_t', 'void *', 'void *', 'void *', 'void *', 'void *']);
// GetNamedSecurityInfoW(pObjectName, ObjectType, SecurityInfo, ppsidOwner, ppsidGroup, ppDacl, ppSacl, ppSecurityDescriptor)
// pObjectName : LPCWSTR -> 'str16'
// 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* out -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("ADVAPI32.dll", {
GetNamedSecurityInfoW: { parameters: ["buffer", "i32", "u32", "pointer", "pointer", "pointer", "pointer", "pointer"], result: "u32" },
});
// lib.symbols.GetNamedSecurityInfoW(pObjectName, ObjectType, SecurityInfo, ppsidOwner, ppsidGroup, ppDacl, ppSacl, ppSecurityDescriptor)
// pObjectName : LPCWSTR -> "buffer"
// 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* out -> "pointer"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
uint32_t GetNamedSecurityInfoW(
const uint16_t* pObjectName,
int32_t ObjectType,
uint32_t SecurityInfo,
void* ppsidOwner,
void* ppsidGroup,
void* ppDacl,
void* ppSacl,
void* ppSecurityDescriptor);
C, "ADVAPI32.dll");
// $ffi->GetNamedSecurityInfoW(pObjectName, ObjectType, SecurityInfo, ppsidOwner, ppsidGroup, ppDacl, ppSacl, ppSecurityDescriptor);
// pObjectName : LPCWSTR
// 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* 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, W32APIOptions.UNICODE_OPTIONS);
int GetNamedSecurityInfoW(
WString pObjectName, // LPCWSTR
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* out
);
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。@[Link("advapi32")]
lib LibADVAPI32
fun GetNamedSecurityInfoW = GetNamedSecurityInfoW(
pObjectName : UInt16*, # LPCWSTR
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* out
) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef GetNamedSecurityInfoWNative = Uint32 Function(Pointer<Utf16>, Int32, Uint32, Pointer<Void>, Pointer<Void>, Pointer<Void>, Pointer<Void>, Pointer<Void>);
typedef GetNamedSecurityInfoWDart = int Function(Pointer<Utf16>, int, int, Pointer<Void>, Pointer<Void>, Pointer<Void>, Pointer<Void>, Pointer<Void>);
final GetNamedSecurityInfoW = DynamicLibrary.open('ADVAPI32.dll')
.lookupFunction<GetNamedSecurityInfoWNative, GetNamedSecurityInfoWDart>('GetNamedSecurityInfoW');
// pObjectName : LPCWSTR -> Pointer<Utf16>
// 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* out -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function GetNamedSecurityInfoW(
pObjectName: PWideChar; // LPCWSTR
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* out
): DWORD; stdcall;
external 'ADVAPI32.dll' name 'GetNamedSecurityInfoW';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "GetNamedSecurityInfoW"
c_GetNamedSecurityInfoW :: CWString -> Int32 -> Word32 -> Ptr () -> Ptr () -> Ptr () -> Ptr () -> Ptr () -> IO Word32
-- pObjectName : LPCWSTR -> CWString
-- 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* out -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let getnamedsecurityinfow =
foreign "GetNamedSecurityInfoW"
((ptr uint16_t) @-> int32_t @-> uint32_t @-> (ptr void) @-> (ptr void) @-> (ptr void) @-> (ptr void) @-> (ptr void) @-> returning uint32_t)
(* pObjectName : LPCWSTR -> (ptr uint16_t) *)
(* 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* 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 ("GetNamedSecurityInfoW" get-named-security-info-w :convention :stdcall) :uint32
(p-object-name (:string :encoding :utf-16le)) ; LPCWSTR
(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* out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $GetNamedSecurityInfoW = Win32::API::More->new('ADVAPI32',
'DWORD GetNamedSecurityInfoW(LPCWSTR pObjectName, int ObjectType, DWORD SecurityInfo, HANDLE ppsidOwner, HANDLE ppsidGroup, LPVOID ppDacl, LPVOID ppSacl, HANDLE ppSecurityDescriptor)');
# my $ret = $GetNamedSecurityInfoW->Call($pObjectName, $ObjectType, $SecurityInfo, $ppsidOwner, $ppsidGroup, $ppDacl, $ppSacl, $ppSecurityDescriptor);
# pObjectName : LPCWSTR -> LPCWSTR
# 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* out -> HANDLE
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。関連項目
- f GetNamedSecurityInfoA (ANSI版) — 名前付きオブジェクトのセキュリティ情報を取得する(ANSI版)。
- f GetSecurityInfo — ハンドルで指定したオブジェクトのセキュリティ情報を取得する。
- f LocalFree — ローカルメモリオブジェクトを解放する。
- s SECURITY_DESCRIPTOR
- s SID
- f SetNamedSecurityInfoW — 名前付きオブジェクトのセキュリティ情報を設定する(Unicode版)。
- f SetSecurityInfo — ハンドルで指定したオブジェクトのセキュリティ情報を設定する。