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関数が SACL を追加する SECURITY_DESCRIPTOR 構造体へのポインターです。このセキュリティ記述子は絶対形式である必要があります。つまり、そのメンバーは連続したデータへのオフセットではなく、他の構造体へのポインターである必要があります。
bSaclPresentBOOLinセキュリティ記述子内に SACL が存在するかどうかを示します。このパラメーターが TRUE の場合、関数は SECURITY_DESCRIPTOR_CONTROL 構造体に SE_SACL_PRESENT フラグを設定し、pSacl および bSaclDefaulted パラメーターの値を使用します。FALSE の場合、関数は SE_SACL_PRESENT フラグを設定せず、pSacl および bSaclDefaulted は無視されます。
pSaclACL*inoptionalセキュリティ記述子の SACL を指定する ACL 構造体へのポインターです。このパラメーターが NULL の場合、NULL SACL がセキュリティ記述子に割り当てられます。SACL はセキュリティ記述子にコピーされるのではなく、参照されます。
bSaclDefaultedBOOLinSACL のソースを示します。このフラグが TRUE の場合、SACL は何らかの既定のメカニズムによって取得されたものです。FALSE の場合、SACL はユーザーによって明示的に指定されたものです。関数はこの値を SECURITY_DESCRIPTOR_CONTROL 構造体の SE_SACL_DEFAULTED フラグに格納します。このパラメーターが指定されない場合、SE_SACL_DEFAULTED フラグはクリアされます。

戻り値の型: BOOL

公式ドキュメント

システムアクセス制御リスト (SACL) に情報を設定します。セキュリティ記述子に既に SACL が存在する場合は、置き換えられます。

戻り値

関数が成功した場合、関数は 0 以外の値を返します。

関数が失敗した場合、0 を返します。拡張エラー情報を取得するには、 GetLastError を呼び出します。

出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)

各言語での呼び出し定義

// 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 <MarshalAs(UnmanagedType.Bool)> 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)。
const std = @import("std");

extern "advapi32" fn SetSecurityDescriptorSacl(
    pSecurityDescriptor: ?*anyopaque, // PSECURITY_DESCRIPTOR in/out
    bSaclPresent: i32, // BOOL
    pSacl: [*c]ACL, // ACL* optional
    bSaclDefaulted: i32 // BOOL
) callconv(std.os.windows.WINAPI) i32;
proc SetSecurityDescriptorSacl(
    pSecurityDescriptor: pointer,  # PSECURITY_DESCRIPTOR in/out
    bSaclPresent: int32,  # BOOL
    pSacl: ptr ACL,  # ACL* optional
    bSaclDefaulted: int32  # BOOL
): int32 {.importc: "SetSecurityDescriptorSacl", stdcall, dynlib: "ADVAPI32.dll".}
pragma(lib, "advapi32");
extern(Windows)
int SetSecurityDescriptorSacl(
    void* pSecurityDescriptor,   // PSECURITY_DESCRIPTOR in/out
    int bSaclPresent,   // BOOL
    ACL* pSacl,   // ACL* optional
    int bSaclDefaulted   // BOOL
);
ccall((:SetSecurityDescriptorSacl, "ADVAPI32.dll"), stdcall, Int32,
      (Ptr{Cvoid}, Int32, Ptr{ACL}, Int32),
      pSecurityDescriptor, bSaclPresent, pSacl, bSaclDefaulted)
# pSecurityDescriptor : PSECURITY_DESCRIPTOR in/out -> Ptr{Cvoid}
# bSaclPresent : BOOL -> Int32
# pSacl : ACL* optional -> Ptr{ACL}
# bSaclDefaulted : BOOL -> Int32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t SetSecurityDescriptorSacl(
    void* pSecurityDescriptor,
    int32_t bSaclPresent,
    void* pSacl,
    int32_t bSaclDefaulted);
]]
local advapi32 = ffi.load("advapi32")
-- advapi32.SetSecurityDescriptorSacl(pSecurityDescriptor, bSaclPresent, pSacl, bSaclDefaulted)
-- pSecurityDescriptor : PSECURITY_DESCRIPTOR in/out
-- bSaclPresent : BOOL
-- pSacl : ACL* optional
-- bSaclDefaulted : BOOL
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('ADVAPI32.dll');
const SetSecurityDescriptorSacl = lib.func('__stdcall', 'SetSecurityDescriptorSacl', 'int32_t', ['void *', 'int32_t', 'void *', 'int32_t']);
// SetSecurityDescriptorSacl(pSecurityDescriptor, bSaclPresent, pSacl, bSaclDefaulted)
// pSecurityDescriptor : PSECURITY_DESCRIPTOR in/out -> 'void *'
// bSaclPresent : BOOL -> 'int32_t'
// pSacl : ACL* optional -> 'void *'
// bSaclDefaulted : BOOL -> 'int32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("ADVAPI32.dll", {
  SetSecurityDescriptorSacl: { parameters: ["pointer", "i32", "pointer", "i32"], result: "i32" },
});
// lib.symbols.SetSecurityDescriptorSacl(pSecurityDescriptor, bSaclPresent, pSacl, bSaclDefaulted)
// pSecurityDescriptor : PSECURITY_DESCRIPTOR in/out -> "pointer"
// bSaclPresent : BOOL -> "i32"
// pSacl : ACL* optional -> "pointer"
// bSaclDefaulted : BOOL -> "i32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t SetSecurityDescriptorSacl(
    void* pSecurityDescriptor,
    int32_t bSaclPresent,
    void* pSacl,
    int32_t bSaclDefaulted);
C, "ADVAPI32.dll");
// $ffi->SetSecurityDescriptorSacl(pSecurityDescriptor, bSaclPresent, pSacl, bSaclDefaulted);
// pSecurityDescriptor : PSECURITY_DESCRIPTOR in/out
// bSaclPresent : BOOL
// pSacl : ACL* optional
// bSaclDefaulted : BOOL
// 構造体/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);
    boolean SetSecurityDescriptorSacl(
        Pointer pSecurityDescriptor,   // PSECURITY_DESCRIPTOR in/out
        boolean bSaclPresent,   // BOOL
        Pointer pSacl,   // ACL* optional
        boolean bSaclDefaulted   // BOOL
    );
}
@[Link("advapi32")]
lib LibADVAPI32
  fun SetSecurityDescriptorSacl = SetSecurityDescriptorSacl(
    pSecurityDescriptor : Void*,   # PSECURITY_DESCRIPTOR in/out
    bSaclPresent : Int32,   # BOOL
    pSacl : ACL*,   # ACL* optional
    bSaclDefaulted : Int32   # BOOL
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef SetSecurityDescriptorSaclNative = Int32 Function(Pointer<Void>, Int32, Pointer<Void>, Int32);
typedef SetSecurityDescriptorSaclDart = int Function(Pointer<Void>, int, Pointer<Void>, int);
final SetSecurityDescriptorSacl = DynamicLibrary.open('ADVAPI32.dll')
    .lookupFunction<SetSecurityDescriptorSaclNative, SetSecurityDescriptorSaclDart>('SetSecurityDescriptorSacl');
// pSecurityDescriptor : PSECURITY_DESCRIPTOR in/out -> Pointer<Void>
// bSaclPresent : BOOL -> Int32
// pSacl : ACL* optional -> Pointer<Void>
// bSaclDefaulted : BOOL -> Int32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
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';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "SetSecurityDescriptorSacl"
  c_SetSecurityDescriptorSacl :: Ptr () -> CInt -> Ptr () -> CInt -> IO CInt
-- pSecurityDescriptor : PSECURITY_DESCRIPTOR in/out -> Ptr ()
-- bSaclPresent : BOOL -> CInt
-- pSacl : ACL* optional -> Ptr ()
-- bSaclDefaulted : BOOL -> CInt
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let setsecuritydescriptorsacl =
  foreign "SetSecurityDescriptorSacl"
    ((ptr void) @-> int32_t @-> (ptr void) @-> int32_t @-> returning int32_t)
(* pSecurityDescriptor : PSECURITY_DESCRIPTOR in/out -> (ptr void) *)
(* bSaclPresent : BOOL -> int32_t *)
(* pSacl : ACL* optional -> (ptr void) *)
(* bSaclDefaulted : BOOL -> int32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library advapi32 (t "ADVAPI32.dll"))
(cffi:use-foreign-library advapi32)

(cffi:defcfun ("SetSecurityDescriptorSacl" set-security-descriptor-sacl :convention :stdcall) :int32
  (p-security-descriptor :pointer)   ; PSECURITY_DESCRIPTOR in/out
  (b-sacl-present :int32)   ; BOOL
  (p-sacl :pointer)   ; ACL* optional
  (b-sacl-defaulted :int32))   ; BOOL
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $SetSecurityDescriptorSacl = Win32::API::More->new('ADVAPI32',
    'BOOL SetSecurityDescriptorSacl(HANDLE pSecurityDescriptor, BOOL bSaclPresent, LPVOID pSacl, BOOL bSaclDefaulted)');
# my $ret = $SetSecurityDescriptorSacl->Call($pSecurityDescriptor, $bSaclPresent, $pSacl, $bSaclDefaulted);
# pSecurityDescriptor : PSECURITY_DESCRIPTOR in/out -> HANDLE
# bSaclPresent : BOOL -> BOOL
# pSacl : ACL* optional -> LPVOID
# bSaclDefaulted : BOOL -> BOOL
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

公式の関連項目
使用する型