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

SetSecurityDescriptorControl

関数
セキュリティ記述子の制御ビットを設定する。
DLLADVAPI32.dll呼出規約winapiSetLastErrorあり対応OSWindows XP 以降

シグネチャ

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

BOOL SetSecurityDescriptorControl(
    PSECURITY_DESCRIPTOR pSecurityDescriptor,
    SECURITY_DESCRIPTOR_CONTROL ControlBitsOfInterest,
    SECURITY_DESCRIPTOR_CONTROL ControlBitsToSet
);

パラメーター

名前方向説明
pSecurityDescriptorPSECURITY_DESCRIPTORin制御情報とリビジョン情報を設定する SECURITY_DESCRIPTOR 構造体へのポインターです。
ControlBitsOfInterestSECURITY_DESCRIPTOR_CONTROLin設定対象の制御ビットを示す SECURITY_DESCRIPTOR_CONTROL マスクです。
ControlBitsToSetSECURITY_DESCRIPTOR_CONTROLinControlBitsOfInterest マスクで指定された制御ビットの新しい値を示す SECURITY_DESCRIPTOR_CONTROL マスクです。

戻り値の型: BOOL

公式ドキュメント

セキュリティ記述子の制御ビットを設定します。この関数で設定できるのは、ACE の自動継承に関連する制御ビットのみです。

戻り値

関数が成功した場合、戻り値は 0 以外です。

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

解説(Remarks)

SetSecurityDescriptorControl 関数では、変更する制御ビットと、そのビットをオンにするかオフにするかを指定します。

次の例では、セキュリティ記述子上の DACL を保護対象としてマークします。

    SetSecurityDescriptorControl( &SecDesc,
            SE_DACL_PROTECTED, SE_DACL_PROTECTED );

次の例では、DACL を保護されていない状態としてマークします。

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

各言語での呼び出し定義

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

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

SetSecurityDescriptorControl = ctypes.windll.advapi32.SetSecurityDescriptorControl
SetSecurityDescriptorControl.restype = wintypes.BOOL
SetSecurityDescriptorControl.argtypes = [
    wintypes.HANDLE,  # pSecurityDescriptor : PSECURITY_DESCRIPTOR
    ctypes.c_ushort,  # ControlBitsOfInterest : SECURITY_DESCRIPTOR_CONTROL
    ctypes.c_ushort,  # ControlBitsToSet : SECURITY_DESCRIPTOR_CONTROL
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('ADVAPI32.dll')
SetSecurityDescriptorControl = Fiddle::Function.new(
  lib['SetSecurityDescriptorControl'],
  [
    Fiddle::TYPE_VOIDP,  # pSecurityDescriptor : PSECURITY_DESCRIPTOR
    -Fiddle::TYPE_SHORT,  # ControlBitsOfInterest : SECURITY_DESCRIPTOR_CONTROL
    -Fiddle::TYPE_SHORT,  # ControlBitsToSet : SECURITY_DESCRIPTOR_CONTROL
  ],
  Fiddle::TYPE_INT)
#[link(name = "advapi32")]
extern "system" {
    fn SetSecurityDescriptorControl(
        pSecurityDescriptor: *mut core::ffi::c_void,  // PSECURITY_DESCRIPTOR
        ControlBitsOfInterest: u16,  // SECURITY_DESCRIPTOR_CONTROL
        ControlBitsToSet: u16  // SECURITY_DESCRIPTOR_CONTROL
    ) -> 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 SetSecurityDescriptorControl(IntPtr pSecurityDescriptor, ushort ControlBitsOfInterest, ushort ControlBitsToSet);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ADVAPI32_SetSecurityDescriptorControl' -Namespace Win32 -PassThru
# $api::SetSecurityDescriptorControl(pSecurityDescriptor, ControlBitsOfInterest, ControlBitsToSet)
#uselib "ADVAPI32.dll"
#func global SetSecurityDescriptorControl "SetSecurityDescriptorControl" sptr, sptr, sptr
; SetSecurityDescriptorControl pSecurityDescriptor, ControlBitsOfInterest, ControlBitsToSet   ; 戻り値は stat
; pSecurityDescriptor : PSECURITY_DESCRIPTOR -> "sptr"
; ControlBitsOfInterest : SECURITY_DESCRIPTOR_CONTROL -> "sptr"
; ControlBitsToSet : SECURITY_DESCRIPTOR_CONTROL -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "ADVAPI32.dll"
#cfunc global SetSecurityDescriptorControl "SetSecurityDescriptorControl" sptr, int, int
; res = SetSecurityDescriptorControl(pSecurityDescriptor, ControlBitsOfInterest, ControlBitsToSet)
; pSecurityDescriptor : PSECURITY_DESCRIPTOR -> "sptr"
; ControlBitsOfInterest : SECURITY_DESCRIPTOR_CONTROL -> "int"
; ControlBitsToSet : SECURITY_DESCRIPTOR_CONTROL -> "int"
; BOOL SetSecurityDescriptorControl(PSECURITY_DESCRIPTOR pSecurityDescriptor, SECURITY_DESCRIPTOR_CONTROL ControlBitsOfInterest, SECURITY_DESCRIPTOR_CONTROL ControlBitsToSet)
#uselib "ADVAPI32.dll"
#cfunc global SetSecurityDescriptorControl "SetSecurityDescriptorControl" intptr, int, int
; res = SetSecurityDescriptorControl(pSecurityDescriptor, ControlBitsOfInterest, ControlBitsToSet)
; pSecurityDescriptor : PSECURITY_DESCRIPTOR -> "intptr"
; ControlBitsOfInterest : SECURITY_DESCRIPTOR_CONTROL -> "int"
; ControlBitsToSet : SECURITY_DESCRIPTOR_CONTROL -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	advapi32 = windows.NewLazySystemDLL("ADVAPI32.dll")
	procSetSecurityDescriptorControl = advapi32.NewProc("SetSecurityDescriptorControl")
)

// pSecurityDescriptor (PSECURITY_DESCRIPTOR), ControlBitsOfInterest (SECURITY_DESCRIPTOR_CONTROL), ControlBitsToSet (SECURITY_DESCRIPTOR_CONTROL)
r1, _, err := procSetSecurityDescriptorControl.Call(
	uintptr(pSecurityDescriptor),
	uintptr(ControlBitsOfInterest),
	uintptr(ControlBitsToSet),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function SetSecurityDescriptorControl(
  pSecurityDescriptor: THandle;   // PSECURITY_DESCRIPTOR
  ControlBitsOfInterest: Word;   // SECURITY_DESCRIPTOR_CONTROL
  ControlBitsToSet: Word   // SECURITY_DESCRIPTOR_CONTROL
): BOOL; stdcall;
  external 'ADVAPI32.dll' name 'SetSecurityDescriptorControl';
result := DllCall("ADVAPI32\SetSecurityDescriptorControl"
    , "Ptr", pSecurityDescriptor   ; PSECURITY_DESCRIPTOR
    , "UShort", ControlBitsOfInterest   ; SECURITY_DESCRIPTOR_CONTROL
    , "UShort", ControlBitsToSet   ; SECURITY_DESCRIPTOR_CONTROL
    , "Int")   ; return: BOOL
●SetSecurityDescriptorControl(pSecurityDescriptor, ControlBitsOfInterest, ControlBitsToSet) = DLL("ADVAPI32.dll", "bool SetSecurityDescriptorControl(void*, int, int)")
# 呼び出し: SetSecurityDescriptorControl(pSecurityDescriptor, ControlBitsOfInterest, ControlBitsToSet)
# pSecurityDescriptor : PSECURITY_DESCRIPTOR -> "void*"
# ControlBitsOfInterest : SECURITY_DESCRIPTOR_CONTROL -> "int"
# ControlBitsToSet : SECURITY_DESCRIPTOR_CONTROL -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

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

typedef SetSecurityDescriptorControlNative = Int32 Function(Pointer<Void>, Uint16, Uint16);
typedef SetSecurityDescriptorControlDart = int Function(Pointer<Void>, int, int);
final SetSecurityDescriptorControl = DynamicLibrary.open('ADVAPI32.dll')
    .lookupFunction<SetSecurityDescriptorControlNative, SetSecurityDescriptorControlDart>('SetSecurityDescriptorControl');
// pSecurityDescriptor : PSECURITY_DESCRIPTOR -> Pointer<Void>
// ControlBitsOfInterest : SECURITY_DESCRIPTOR_CONTROL -> Uint16
// ControlBitsToSet : SECURITY_DESCRIPTOR_CONTROL -> Uint16
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function SetSecurityDescriptorControl(
  pSecurityDescriptor: THandle;   // PSECURITY_DESCRIPTOR
  ControlBitsOfInterest: Word;   // SECURITY_DESCRIPTOR_CONTROL
  ControlBitsToSet: Word   // SECURITY_DESCRIPTOR_CONTROL
): BOOL; stdcall;
  external 'ADVAPI32.dll' name 'SetSecurityDescriptorControl';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "SetSecurityDescriptorControl"
  c_SetSecurityDescriptorControl :: Ptr () -> Word16 -> Word16 -> IO CInt
-- pSecurityDescriptor : PSECURITY_DESCRIPTOR -> Ptr ()
-- ControlBitsOfInterest : SECURITY_DESCRIPTOR_CONTROL -> Word16
-- ControlBitsToSet : SECURITY_DESCRIPTOR_CONTROL -> Word16
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let setsecuritydescriptorcontrol =
  foreign "SetSecurityDescriptorControl"
    ((ptr void) @-> uint16_t @-> uint16_t @-> returning int32_t)
(* pSecurityDescriptor : PSECURITY_DESCRIPTOR -> (ptr void) *)
(* ControlBitsOfInterest : SECURITY_DESCRIPTOR_CONTROL -> uint16_t *)
(* ControlBitsToSet : SECURITY_DESCRIPTOR_CONTROL -> uint16_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library advapi32 (t "ADVAPI32.dll"))
(cffi:use-foreign-library advapi32)

(cffi:defcfun ("SetSecurityDescriptorControl" set-security-descriptor-control :convention :stdcall) :int32
  (p-security-descriptor :pointer)   ; PSECURITY_DESCRIPTOR
  (control-bits-of-interest :uint16)   ; SECURITY_DESCRIPTOR_CONTROL
  (control-bits-to-set :uint16))   ; SECURITY_DESCRIPTOR_CONTROL
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $SetSecurityDescriptorControl = Win32::API::More->new('ADVAPI32',
    'BOOL SetSecurityDescriptorControl(HANDLE pSecurityDescriptor, WORD ControlBitsOfInterest, WORD ControlBitsToSet)');
# my $ret = $SetSecurityDescriptorControl->Call($pSecurityDescriptor, $ControlBitsOfInterest, $ControlBitsToSet);
# pSecurityDescriptor : PSECURITY_DESCRIPTOR -> HANDLE
# ControlBitsOfInterest : SECURITY_DESCRIPTOR_CONTROL -> WORD
# ControlBitsToSet : SECURITY_DESCRIPTOR_CONTROL -> WORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

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