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

SetSecurityDescriptorSacl

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

シグネチャ

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

BOOL SetSecurityDescriptorSacl(
    PSECURITY_DESCRIPTOR pSecurityDescriptor,
    BOOL bSaclPresent,
    ACL* pSacl,   // optional
    BOOL bSaclDefaulted
);

パラメーター

名前方向
pSecurityDescriptorPSECURITY_DESCRIPTORinout
bSaclPresentBOOLin
pSaclACL*inoptional
bSaclDefaultedBOOLin

戻り値の型: BOOL

各言語での呼び出し定義

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

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

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

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

var (
	advapi32 = windows.NewLazySystemDLL("ADVAPI32.dll")
	procSetSecurityDescriptorSacl = advapi32.NewProc("SetSecurityDescriptorSacl")
)

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