SetSecurityDescriptorDacl
関数セキュリティ記述子にDACL(任意アクセス制御リスト)を設定する。
シグネチャ
// ADVAPI32.dll
#include <windows.h>
BOOL SetSecurityDescriptorDacl(
PSECURITY_DESCRIPTOR pSecurityDescriptor,
BOOL bDaclPresent,
ACL* pDacl, // optional
BOOL bDaclDefaulted
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| pSecurityDescriptor | PSECURITY_DESCRIPTOR | inout | 関数が DACL を追加する対象の SECURITY_DESCRIPTOR 構造体へのポインターです。このセキュリティ記述子は 絶対 (absolute) 形式である必要があります。つまり、そのメンバーは連続したデータへのオフセットではなく、他の構造体へのポインターである必要があります。 |
| bDaclPresent | BOOL | in | セキュリティ記述子に DACL が存在することを示すフラグです。このパラメーターが TRUE の場合、関数は SECURITY_DESCRIPTOR_CONTROL 構造体の SE_DACL_PRESENT フラグを設定し、pDacl および bDaclDefaulted パラメーターの値を使用します。このパラメーターが FALSE の場合、関数は SE_DACL_PRESENT フラグをクリアし、pDacl および bDaclDefaulted は無視されます。 |
| pDacl | ACL* | inoptional | セキュリティ記述子の DACL を指定する ACL 構造体へのポインターです。このパラメーターが NULL の場合、セキュリティ記述子には NULL DACL が割り当てられ、オブジェクトへのすべてのアクセスが許可されます。DACL はセキュリティ記述子にコピーされるのではなく、参照されます。 |
| bDaclDefaulted | BOOL | in | DACL の取得元を示すフラグです。このフラグが TRUE の場合、DACL は何らかの既定のメカニズムによって取得されたものです。FALSE の場合、DACL はユーザーによって明示的に指定されたものです。関数はこの値を SECURITY_DESCRIPTOR_CONTROL 構造体の SE_DACL_DEFAULTED フラグに格納します。このパラメーターが指定されない場合、SE_DACL_DEFAULTED フラグはクリアされます。 |
戻り値の型: BOOL
公式ドキュメント
任意アクセス制御リスト (DACL) に情報を設定します。セキュリティ記述子に既に DACL が存在する場合、その DACL は置き換えられます。
戻り値
関数が成功した場合、関数は 0 以外の値を返します。
関数が失敗した場合、0 を返します。拡張エラー情報を取得するには、 GetLastError を呼び出します。
解説(Remarks)
空の DACL と存在しない DACL の間には重要な違いがあります。DACL が空の場合、アクセス制御エントリ (ACE) を含まないため、アクセス権が明示的に付与されません。その結果、オブジェクトへのアクセスは暗黙的に拒否されます。
オブジェクトに DACL がない場合 (pDacl パラメーターが NULL の場合)、オブジェクトには保護が割り当てられず、すべてのアクセス要求が許可されます。セキュリティを維持するために、DACL を使用してアクセスを制限してください。
bDaclPresent フラグと pDacl パラメーターの構成の違いにより、3 つの結果が考えられます。
- pDacl パラメーターが DACL を指し、bDaclPresent フラグが TRUE の場合、DACL が指定されます。オブジェクトへのアクセスを許可するには、その DACL にアクセス許可 ACE が含まれている必要があります。
- pDacl パラメーターが DACL を指さず、bDaclPresent フラグが TRUE の場合、NULL DACL が指定されます。すべてのアクセスが許可されます。どのユーザーもセキュリティ記述子の DACL と所有者を変更できるため、オブジェクトに NULL DACL を使用しないでください。これはオブジェクトの使用に支障をきたします。
- pDacl パラメーターが DACL を指さず、bDaclPresent フラグが FALSE の場合、継承または既定のメカニズムを通じてオブジェクトに DACL を提供できます。
例
この関数を使用する例については、新しいオブジェクトのセキュリティ記述子の作成を参照してください。
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// 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 <MarshalAs(UnmanagedType.Bool)> 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 方式にも切替可。#uselib "ADVAPI32.dll" #cfunc global SetSecurityDescriptorDacl "SetSecurityDescriptorDacl" sptr, int, sptr, int ; res = SetSecurityDescriptorDacl(pSecurityDescriptor, bDaclPresent, varptr(pDacl), bDaclDefaulted) ; pSecurityDescriptor : PSECURITY_DESCRIPTOR in/out -> "sptr" ; bDaclPresent : BOOL -> "int" ; pDacl : ACL* optional -> "sptr" ; bDaclDefaulted : BOOL -> "int" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは 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 方式にも切替可。; BOOL SetSecurityDescriptorDacl(PSECURITY_DESCRIPTOR pSecurityDescriptor, BOOL bDaclPresent, ACL* pDacl, BOOL bDaclDefaulted) #uselib "ADVAPI32.dll" #cfunc global SetSecurityDescriptorDacl "SetSecurityDescriptorDacl" intptr, int, intptr, int ; res = SetSecurityDescriptorDacl(pSecurityDescriptor, bDaclPresent, varptr(pDacl), bDaclDefaulted) ; pSecurityDescriptor : PSECURITY_DESCRIPTOR in/out -> "intptr" ; bDaclPresent : BOOL -> "int" ; pDacl : ACL* optional -> "intptr" ; bDaclDefaulted : BOOL -> "int" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは 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 // BOOLfunction 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)。const std = @import("std");
extern "advapi32" fn SetSecurityDescriptorDacl(
pSecurityDescriptor: ?*anyopaque, // PSECURITY_DESCRIPTOR in/out
bDaclPresent: i32, // BOOL
pDacl: [*c]ACL, // ACL* optional
bDaclDefaulted: i32 // BOOL
) callconv(std.os.windows.WINAPI) i32;proc SetSecurityDescriptorDacl(
pSecurityDescriptor: pointer, # PSECURITY_DESCRIPTOR in/out
bDaclPresent: int32, # BOOL
pDacl: ptr ACL, # ACL* optional
bDaclDefaulted: int32 # BOOL
): int32 {.importc: "SetSecurityDescriptorDacl", stdcall, dynlib: "ADVAPI32.dll".}pragma(lib, "advapi32");
extern(Windows)
int SetSecurityDescriptorDacl(
void* pSecurityDescriptor, // PSECURITY_DESCRIPTOR in/out
int bDaclPresent, // BOOL
ACL* pDacl, // ACL* optional
int bDaclDefaulted // BOOL
);ccall((:SetSecurityDescriptorDacl, "ADVAPI32.dll"), stdcall, Int32,
(Ptr{Cvoid}, Int32, Ptr{ACL}, Int32),
pSecurityDescriptor, bDaclPresent, pDacl, bDaclDefaulted)
# pSecurityDescriptor : PSECURITY_DESCRIPTOR in/out -> Ptr{Cvoid}
# bDaclPresent : BOOL -> Int32
# pDacl : ACL* optional -> Ptr{ACL}
# bDaclDefaulted : BOOL -> Int32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t SetSecurityDescriptorDacl(
void* pSecurityDescriptor,
int32_t bDaclPresent,
void* pDacl,
int32_t bDaclDefaulted);
]]
local advapi32 = ffi.load("advapi32")
-- advapi32.SetSecurityDescriptorDacl(pSecurityDescriptor, bDaclPresent, pDacl, bDaclDefaulted)
-- pSecurityDescriptor : PSECURITY_DESCRIPTOR in/out
-- bDaclPresent : BOOL
-- pDacl : ACL* optional
-- bDaclDefaulted : BOOL
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('ADVAPI32.dll');
const SetSecurityDescriptorDacl = lib.func('__stdcall', 'SetSecurityDescriptorDacl', 'int32_t', ['void *', 'int32_t', 'void *', 'int32_t']);
// SetSecurityDescriptorDacl(pSecurityDescriptor, bDaclPresent, pDacl, bDaclDefaulted)
// pSecurityDescriptor : PSECURITY_DESCRIPTOR in/out -> 'void *'
// bDaclPresent : BOOL -> 'int32_t'
// pDacl : ACL* optional -> 'void *'
// bDaclDefaulted : BOOL -> 'int32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("ADVAPI32.dll", {
SetSecurityDescriptorDacl: { parameters: ["pointer", "i32", "pointer", "i32"], result: "i32" },
});
// lib.symbols.SetSecurityDescriptorDacl(pSecurityDescriptor, bDaclPresent, pDacl, bDaclDefaulted)
// pSecurityDescriptor : PSECURITY_DESCRIPTOR in/out -> "pointer"
// bDaclPresent : BOOL -> "i32"
// pDacl : ACL* optional -> "pointer"
// bDaclDefaulted : BOOL -> "i32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t SetSecurityDescriptorDacl(
void* pSecurityDescriptor,
int32_t bDaclPresent,
void* pDacl,
int32_t bDaclDefaulted);
C, "ADVAPI32.dll");
// $ffi->SetSecurityDescriptorDacl(pSecurityDescriptor, bDaclPresent, pDacl, bDaclDefaulted);
// pSecurityDescriptor : PSECURITY_DESCRIPTOR in/out
// bDaclPresent : BOOL
// pDacl : ACL* optional
// bDaclDefaulted : 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 SetSecurityDescriptorDacl(
Pointer pSecurityDescriptor, // PSECURITY_DESCRIPTOR in/out
boolean bDaclPresent, // BOOL
Pointer pDacl, // ACL* optional
boolean bDaclDefaulted // BOOL
);
}@[Link("advapi32")]
lib LibADVAPI32
fun SetSecurityDescriptorDacl = SetSecurityDescriptorDacl(
pSecurityDescriptor : Void*, # PSECURITY_DESCRIPTOR in/out
bDaclPresent : Int32, # BOOL
pDacl : ACL*, # ACL* optional
bDaclDefaulted : 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 SetSecurityDescriptorDaclNative = Int32 Function(Pointer<Void>, Int32, Pointer<Void>, Int32);
typedef SetSecurityDescriptorDaclDart = int Function(Pointer<Void>, int, Pointer<Void>, int);
final SetSecurityDescriptorDacl = DynamicLibrary.open('ADVAPI32.dll')
.lookupFunction<SetSecurityDescriptorDaclNative, SetSecurityDescriptorDaclDart>('SetSecurityDescriptorDacl');
// pSecurityDescriptor : PSECURITY_DESCRIPTOR in/out -> Pointer<Void>
// bDaclPresent : BOOL -> Int32
// pDacl : ACL* optional -> Pointer<Void>
// bDaclDefaulted : BOOL -> Int32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
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';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "SetSecurityDescriptorDacl"
c_SetSecurityDescriptorDacl :: Ptr () -> CInt -> Ptr () -> CInt -> IO CInt
-- pSecurityDescriptor : PSECURITY_DESCRIPTOR in/out -> Ptr ()
-- bDaclPresent : BOOL -> CInt
-- pDacl : ACL* optional -> Ptr ()
-- bDaclDefaulted : BOOL -> CInt
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let setsecuritydescriptordacl =
foreign "SetSecurityDescriptorDacl"
((ptr void) @-> int32_t @-> (ptr void) @-> int32_t @-> returning int32_t)
(* pSecurityDescriptor : PSECURITY_DESCRIPTOR in/out -> (ptr void) *)
(* bDaclPresent : BOOL -> int32_t *)
(* pDacl : ACL* optional -> (ptr void) *)
(* bDaclDefaulted : 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 ("SetSecurityDescriptorDacl" set-security-descriptor-dacl :convention :stdcall) :int32
(p-security-descriptor :pointer) ; PSECURITY_DESCRIPTOR in/out
(b-dacl-present :int32) ; BOOL
(p-dacl :pointer) ; ACL* optional
(b-dacl-defaulted :int32)) ; BOOL
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $SetSecurityDescriptorDacl = Win32::API::More->new('ADVAPI32',
'BOOL SetSecurityDescriptorDacl(HANDLE pSecurityDescriptor, BOOL bDaclPresent, LPVOID pDacl, BOOL bDaclDefaulted)');
# my $ret = $SetSecurityDescriptorDacl->Call($pSecurityDescriptor, $bDaclPresent, $pDacl, $bDaclDefaulted);
# pSecurityDescriptor : PSECURITY_DESCRIPTOR in/out -> HANDLE
# bDaclPresent : BOOL -> BOOL
# pDacl : ACL* optional -> LPVOID
# bDaclDefaulted : BOOL -> BOOL
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
公式の関連項目
- f GetSecurityDescriptorDacl — セキュリティ記述子からDACLを取得する。
- f InitializeSecurityDescriptor — 新しいセキュリティ記述子を初期化する。
- f IsValidSecurityDescriptor — セキュリティ記述子が有効かどうかを検証する。
- s SECURITY_DESCRIPTOR
- f SetSecurityDescriptorGroup — セキュリティ記述子のプライマリグループSIDを設定する。
- f SetSecurityDescriptorOwner — セキュリティ記述子の所有者SIDを設定する。
- f SetSecurityDescriptorSacl — セキュリティ記述子にSACL(システムアクセス制御リスト)を設定する。
使用する型