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

SetSecurityDescriptorDacl

関数
セキュリティ記述子にDACL(任意アクセス制御リスト)を設定する。
DLLADVAPI32.dll呼出規約winapiSetLastErrorあり対応OSWindows XP 以降

シグネチャ

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

BOOL SetSecurityDescriptorDacl(
    PSECURITY_DESCRIPTOR pSecurityDescriptor,
    BOOL bDaclPresent,
    ACL* pDacl,   // optional
    BOOL bDaclDefaulted
);

パラメーター

名前方向
pSecurityDescriptorPSECURITY_DESCRIPTORinout
bDaclPresentBOOLin
pDaclACL*inoptional
bDaclDefaultedBOOLin

戻り値の型: BOOL

各言語での呼び出し定義

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

BOOL SetSecurityDescriptorDacl(
    PSECURITY_DESCRIPTOR pSecurityDescriptor,
    BOOL bDaclPresent,
    ACL* pDacl,   // optional
    BOOL bDaclDefaulted
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("ADVAPI32.dll", SetLastError = true, ExactSpelling = true)]
static extern bool SetSecurityDescriptorDacl(
    IntPtr pSecurityDescriptor,   // PSECURITY_DESCRIPTOR in/out
    bool bDaclPresent,   // BOOL
    IntPtr pDacl,   // ACL* optional
    bool bDaclDefaulted   // BOOL
);
<DllImport("ADVAPI32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function SetSecurityDescriptorDacl(
    pSecurityDescriptor As IntPtr,   ' PSECURITY_DESCRIPTOR in/out
    bDaclPresent As Boolean,   ' BOOL
    pDacl As IntPtr,   ' ACL* optional
    bDaclDefaulted As Boolean   ' BOOL
) As Boolean
End Function
' pSecurityDescriptor : PSECURITY_DESCRIPTOR in/out
' bDaclPresent : BOOL
' pDacl : ACL* optional
' bDaclDefaulted : BOOL
Declare PtrSafe Function SetSecurityDescriptorDacl Lib "advapi32" ( _
    ByVal pSecurityDescriptor As LongPtr, _
    ByVal bDaclPresent As Long, _
    ByVal pDacl As LongPtr, _
    ByVal bDaclDefaulted As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

SetSecurityDescriptorDacl = ctypes.windll.advapi32.SetSecurityDescriptorDacl
SetSecurityDescriptorDacl.restype = wintypes.BOOL
SetSecurityDescriptorDacl.argtypes = [
    wintypes.HANDLE,  # pSecurityDescriptor : PSECURITY_DESCRIPTOR in/out
    wintypes.BOOL,  # bDaclPresent : BOOL
    ctypes.c_void_p,  # pDacl : ACL* optional
    wintypes.BOOL,  # bDaclDefaulted : BOOL
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('ADVAPI32.dll')
SetSecurityDescriptorDacl = Fiddle::Function.new(
  lib['SetSecurityDescriptorDacl'],
  [
    Fiddle::TYPE_VOIDP,  # pSecurityDescriptor : PSECURITY_DESCRIPTOR in/out
    Fiddle::TYPE_INT,  # bDaclPresent : BOOL
    Fiddle::TYPE_VOIDP,  # pDacl : ACL* optional
    Fiddle::TYPE_INT,  # bDaclDefaulted : BOOL
  ],
  Fiddle::TYPE_INT)
#[link(name = "advapi32")]
extern "system" {
    fn SetSecurityDescriptorDacl(
        pSecurityDescriptor: *mut core::ffi::c_void,  // PSECURITY_DESCRIPTOR in/out
        bDaclPresent: i32,  // BOOL
        pDacl: *mut ACL,  // ACL* optional
        bDaclDefaulted: i32  // BOOL
    ) -> 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 SetSecurityDescriptorDacl(IntPtr pSecurityDescriptor, bool bDaclPresent, IntPtr pDacl, bool bDaclDefaulted);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ADVAPI32_SetSecurityDescriptorDacl' -Namespace Win32 -PassThru
# $api::SetSecurityDescriptorDacl(pSecurityDescriptor, bDaclPresent, pDacl, bDaclDefaulted)
#uselib "ADVAPI32.dll"
#func global SetSecurityDescriptorDacl "SetSecurityDescriptorDacl" sptr, sptr, sptr, sptr
; SetSecurityDescriptorDacl pSecurityDescriptor, bDaclPresent, varptr(pDacl), bDaclDefaulted   ; 戻り値は stat
; pSecurityDescriptor : PSECURITY_DESCRIPTOR in/out -> "sptr"
; bDaclPresent : BOOL -> "sptr"
; pDacl : ACL* optional -> "sptr"
; bDaclDefaulted : BOOL -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "ADVAPI32.dll"
#cfunc global SetSecurityDescriptorDacl "SetSecurityDescriptorDacl" sptr, int, var, int
; res = SetSecurityDescriptorDacl(pSecurityDescriptor, bDaclPresent, pDacl, bDaclDefaulted)
; pSecurityDescriptor : PSECURITY_DESCRIPTOR in/out -> "sptr"
; bDaclPresent : BOOL -> "int"
; pDacl : ACL* optional -> "var"
; bDaclDefaulted : BOOL -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; BOOL SetSecurityDescriptorDacl(PSECURITY_DESCRIPTOR pSecurityDescriptor, BOOL bDaclPresent, ACL* pDacl, BOOL bDaclDefaulted)
#uselib "ADVAPI32.dll"
#cfunc global SetSecurityDescriptorDacl "SetSecurityDescriptorDacl" intptr, int, var, int
; res = SetSecurityDescriptorDacl(pSecurityDescriptor, bDaclPresent, pDacl, bDaclDefaulted)
; pSecurityDescriptor : PSECURITY_DESCRIPTOR in/out -> "intptr"
; bDaclPresent : BOOL -> "int"
; pDacl : ACL* optional -> "var"
; bDaclDefaulted : BOOL -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	advapi32 = windows.NewLazySystemDLL("ADVAPI32.dll")
	procSetSecurityDescriptorDacl = advapi32.NewProc("SetSecurityDescriptorDacl")
)

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