GetFileSecurityA
関数指定ファイルのセキュリティ記述子を取得する(ANSI版)。
シグネチャ
// ADVAPI32.dll (ANSI / -A)
#include <windows.h>
BOOL GetFileSecurityA(
LPCSTR lpFileName,
DWORD RequestedInformation,
PSECURITY_DESCRIPTOR pSecurityDescriptor, // optional
DWORD nLength,
DWORD* lpnLengthNeeded
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| lpFileName | LPCSTR | in |
| RequestedInformation | DWORD | in |
| pSecurityDescriptor | PSECURITY_DESCRIPTOR | outoptional |
| nLength | DWORD | in |
| lpnLengthNeeded | DWORD* | out |
戻り値の型: BOOL
各言語での呼び出し定義
// ADVAPI32.dll (ANSI / -A)
#include <windows.h>
BOOL GetFileSecurityA(
LPCSTR lpFileName,
DWORD RequestedInformation,
PSECURITY_DESCRIPTOR pSecurityDescriptor, // optional
DWORD nLength,
DWORD* lpnLengthNeeded
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("ADVAPI32.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
static extern bool GetFileSecurityA(
[MarshalAs(UnmanagedType.LPStr)] string lpFileName, // LPCSTR
uint RequestedInformation, // DWORD
IntPtr pSecurityDescriptor, // PSECURITY_DESCRIPTOR optional, out
uint nLength, // DWORD
out uint lpnLengthNeeded // DWORD* out
);<DllImport("ADVAPI32.dll", CharSet:=CharSet.Ansi, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function GetFileSecurityA(
<MarshalAs(UnmanagedType.LPStr)> lpFileName As String, ' LPCSTR
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' lpFileName : LPCSTR
' RequestedInformation : DWORD
' pSecurityDescriptor : PSECURITY_DESCRIPTOR optional, out
' nLength : DWORD
' lpnLengthNeeded : DWORD* out
Declare PtrSafe Function GetFileSecurityA Lib "advapi32" ( _
ByVal lpFileName As String, _
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
GetFileSecurityA = ctypes.windll.advapi32.GetFileSecurityA
GetFileSecurityA.restype = wintypes.BOOL
GetFileSecurityA.argtypes = [
wintypes.LPCSTR, # lpFileName : LPCSTR
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')
GetFileSecurityA = Fiddle::Function.new(
lib['GetFileSecurityA'],
[
Fiddle::TYPE_VOIDP, # lpFileName : LPCSTR
-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 GetFileSecurityA(
lpFileName: *const u8, // LPCSTR
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", CharSet = CharSet.Ansi, SetLastError = true)]
public static extern bool GetFileSecurityA([MarshalAs(UnmanagedType.LPStr)] string lpFileName, uint RequestedInformation, IntPtr pSecurityDescriptor, uint nLength, out uint lpnLengthNeeded);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ADVAPI32_GetFileSecurityA' -Namespace Win32 -PassThru
# $api::GetFileSecurityA(lpFileName, RequestedInformation, pSecurityDescriptor, nLength, lpnLengthNeeded)#uselib "ADVAPI32.dll"
#func global GetFileSecurityA "GetFileSecurityA" sptr, sptr, sptr, sptr, sptr
; GetFileSecurityA lpFileName, RequestedInformation, pSecurityDescriptor, nLength, varptr(lpnLengthNeeded) ; 戻り値は stat
; lpFileName : LPCSTR -> "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 GetFileSecurityA "GetFileSecurityA" str, int, sptr, int, var ; res = GetFileSecurityA(lpFileName, RequestedInformation, pSecurityDescriptor, nLength, lpnLengthNeeded) ; lpFileName : LPCSTR -> "str" ; RequestedInformation : DWORD -> "int" ; pSecurityDescriptor : PSECURITY_DESCRIPTOR optional, out -> "sptr" ; nLength : DWORD -> "int" ; lpnLengthNeeded : DWORD* out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "ADVAPI32.dll" #cfunc global GetFileSecurityA "GetFileSecurityA" str, int, sptr, int, sptr ; res = GetFileSecurityA(lpFileName, RequestedInformation, pSecurityDescriptor, nLength, varptr(lpnLengthNeeded)) ; lpFileName : LPCSTR -> "str" ; RequestedInformation : DWORD -> "int" ; pSecurityDescriptor : PSECURITY_DESCRIPTOR optional, out -> "sptr" ; nLength : DWORD -> "int" ; lpnLengthNeeded : DWORD* out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; BOOL GetFileSecurityA(LPCSTR lpFileName, DWORD RequestedInformation, PSECURITY_DESCRIPTOR pSecurityDescriptor, DWORD nLength, DWORD* lpnLengthNeeded) #uselib "ADVAPI32.dll" #cfunc global GetFileSecurityA "GetFileSecurityA" str, int, intptr, int, var ; res = GetFileSecurityA(lpFileName, RequestedInformation, pSecurityDescriptor, nLength, lpnLengthNeeded) ; lpFileName : LPCSTR -> "str" ; RequestedInformation : DWORD -> "int" ; pSecurityDescriptor : PSECURITY_DESCRIPTOR optional, out -> "intptr" ; nLength : DWORD -> "int" ; lpnLengthNeeded : DWORD* out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; BOOL GetFileSecurityA(LPCSTR lpFileName, DWORD RequestedInformation, PSECURITY_DESCRIPTOR pSecurityDescriptor, DWORD nLength, DWORD* lpnLengthNeeded) #uselib "ADVAPI32.dll" #cfunc global GetFileSecurityA "GetFileSecurityA" str, int, intptr, int, intptr ; res = GetFileSecurityA(lpFileName, RequestedInformation, pSecurityDescriptor, nLength, varptr(lpnLengthNeeded)) ; lpFileName : LPCSTR -> "str" ; RequestedInformation : DWORD -> "int" ; pSecurityDescriptor : PSECURITY_DESCRIPTOR optional, out -> "intptr" ; nLength : DWORD -> "int" ; lpnLengthNeeded : DWORD* out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
advapi32 = windows.NewLazySystemDLL("ADVAPI32.dll")
procGetFileSecurityA = advapi32.NewProc("GetFileSecurityA")
)
// lpFileName (LPCSTR), RequestedInformation (DWORD), pSecurityDescriptor (PSECURITY_DESCRIPTOR optional, out), nLength (DWORD), lpnLengthNeeded (DWORD* out)
r1, _, err := procGetFileSecurityA.Call(
uintptr(unsafe.Pointer(windows.BytePtrFromString(lpFileName))),
uintptr(RequestedInformation),
uintptr(pSecurityDescriptor),
uintptr(nLength),
uintptr(lpnLengthNeeded),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction GetFileSecurityA(
lpFileName: PAnsiChar; // LPCSTR
RequestedInformation: DWORD; // DWORD
pSecurityDescriptor: THandle; // PSECURITY_DESCRIPTOR optional, out
nLength: DWORD; // DWORD
lpnLengthNeeded: Pointer // DWORD* out
): BOOL; stdcall;
external 'ADVAPI32.dll' name 'GetFileSecurityA';result := DllCall("ADVAPI32\GetFileSecurityA"
, "AStr", lpFileName ; LPCSTR
, "UInt", RequestedInformation ; DWORD
, "Ptr", pSecurityDescriptor ; PSECURITY_DESCRIPTOR optional, out
, "UInt", nLength ; DWORD
, "Ptr", lpnLengthNeeded ; DWORD* out
, "Int") ; return: BOOL●GetFileSecurityA(lpFileName, RequestedInformation, pSecurityDescriptor, nLength, lpnLengthNeeded) = DLL("ADVAPI32.dll", "bool GetFileSecurityA(char*, dword, void*, dword, void*)")
# 呼び出し: GetFileSecurityA(lpFileName, RequestedInformation, pSecurityDescriptor, nLength, lpnLengthNeeded)
# lpFileName : LPCSTR -> "char*"
# 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)。