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

ConvertToAutoInheritPrivateObjectSecurity

関数
セキュリティ記述子を自動継承形式に変換する。
DLLADVAPI32.dll呼出規約winapiSetLastErrorあり対応OSWindows XP 以降

シグネチャ

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

BOOL ConvertToAutoInheritPrivateObjectSecurity(
    PSECURITY_DESCRIPTOR ParentDescriptor,   // optional
    PSECURITY_DESCRIPTOR CurrentSecurityDescriptor,
    PSECURITY_DESCRIPTOR* NewSecurityDescriptor,
    GUID* ObjectType,   // optional
    BOOLEAN IsDirectoryObject,
    GENERIC_MAPPING* GenericMapping
);

パラメーター

名前方向説明
ParentDescriptorPSECURITY_DESCRIPTORinoptionalオブジェクトの親コンテナーの security descriptor へのポインター。親コンテナーが存在しない場合、このパラメーターは NULL です。
CurrentSecurityDescriptorPSECURITY_DESCRIPTORinオブジェクトの現在のセキュリティ記述子へのポインター。
NewSecurityDescriptorPSECURITY_DESCRIPTOR*out新しく割り当てられた self-relative security descriptor へのポインターを受け取る変数へのポインター。このセキュリティ記述子を解放するために DestroyPrivateObjectSecurity 関数を呼び出すのは、呼び出し元の責任です。
ObjectTypeGUID*inoptionalCurrentSecurityDescriptor パラメーターに関連付けられたオブジェクトの種類を識別する GUID 構造体へのポインター。オブジェクトが GUID を持たない場合、このパラメーターは NULL でなければなりません。
IsDirectoryObjectBOOLEANinTRUE の場合、新しいオブジェクトはコンテナーであり、他のオブジェクトを格納できます。FALSE の場合、新しいオブジェクトはコンテナーではありません。
GenericMappingGENERIC_MAPPING*inオブジェクトの各ジェネリック権利から特定の権利へのマッピングを指定する GENERIC_MAPPING 構造体へのポインター。

戻り値の型: BOOL

公式ドキュメント

セキュリティ記述子とそのアクセス制御リスト (ACL) を、継承可能なアクセス制御エントリ (ACE) の自動的な伝播をサポートする形式に変換します。

戻り値

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

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

解説(Remarks)

ConvertToAutoInheritPrivateObjectSecurity 関数は、現在のセキュリティ記述子の discretionary access control list (DACL) および system access control list (SACL) 内の ACE が、親セキュリティ記述子から継承されたものかどうかを判定しようとします。この関数は ParentDescriptor パラメーターを CreatePrivateObjectSecurityEx 関数に渡して、継承された ACE のみを含む ACL を取得します。次に、これらの ACE を元のセキュリティ記述子内の ACE と比較し、元の ACE のうちどれが継承されたものかを判定します。ACE は 1 対 1 で一致する必要はありません。たとえば、あるトラスティに読み取りと書き込みのアクセスを許可する 1 つの ACE は、読み取りアクセスを許可する ACE と書き込みアクセスを許可する ACE の 2 つの ACE と等価になり得ます。

親セキュリティ記述子から継承された ACE と等価な、元のセキュリティ記述子内の ACE には INHERITED_ACE フラグが付与され、新しいセキュリティ記述子に追加されます。元のセキュリティ記述子内のその他のすべての ACE は、継承されていない ACE として新しいセキュリティ記述子に追加されます。

元の DACL に継承された ACE が 1 つもない場合、関数は新しいセキュリティ記述子の制御ビットに SE_DACL_PROTECTED フラグを設定します。同様に、SACL 内のどの ACE も継承されていない場合は SE_SACL_PROTECTED フラグが設定されます。

継承された ACE を持つ DACL について、関数は ACE を 2 つのグループに並べ替えます。最初のグループには、オブジェクトに直接適用された ACE が含まれます。2 番目のグループには継承された ACE が含まれます。この順序付けにより、継承されていない ACE が継承された ACE よりも優先されることが保証されます。詳細については、 Order of ACEs in a DACL を参照してください。

関数は、新しいセキュリティ記述子の制御ビットに SE_DACL_AUTO_INHERITED フラグおよび SE_SACL_AUTO_INHERITED フラグを設定します。

関数は、DACL 内のアクセス許可 ACE とアクセス拒否 ACE の相対的な順序を変更しません。順序を変更すると、結果として得られるセキュリティ記述子のセマンティクスが変わってしまうためです。セマンティクスを変えずに DACL を変換できない場合、関数は DACL を変更せずそのままにし、SE_DACL_PROTECTED フラグを設定します。

新しいセキュリティ記述子は、元のセキュリティ記述子と同じ所有者およびプライマリ グループを持ちます。

新しいセキュリティ記述子は元のセキュリティ記述子と等価であるため、呼び出し元はセキュリティ記述子を新しい形式に更新するためのアクセス権や privileges を必要としません。

この関数は ACL_REVISION および ACL_REVISION_DS の ACL で動作します。

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

各言語での呼び出し定義

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

BOOL ConvertToAutoInheritPrivateObjectSecurity(
    PSECURITY_DESCRIPTOR ParentDescriptor,   // optional
    PSECURITY_DESCRIPTOR CurrentSecurityDescriptor,
    PSECURITY_DESCRIPTOR* NewSecurityDescriptor,
    GUID* ObjectType,   // optional
    BOOLEAN IsDirectoryObject,
    GENERIC_MAPPING* GenericMapping
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("ADVAPI32.dll", SetLastError = true, ExactSpelling = true)]
static extern bool ConvertToAutoInheritPrivateObjectSecurity(
    IntPtr ParentDescriptor,   // PSECURITY_DESCRIPTOR optional
    IntPtr CurrentSecurityDescriptor,   // PSECURITY_DESCRIPTOR
    IntPtr NewSecurityDescriptor,   // PSECURITY_DESCRIPTOR* out
    IntPtr ObjectType,   // GUID* optional
    [MarshalAs(UnmanagedType.U1)] bool IsDirectoryObject,   // BOOLEAN
    IntPtr GenericMapping   // GENERIC_MAPPING*
);
<DllImport("ADVAPI32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function ConvertToAutoInheritPrivateObjectSecurity(
    ParentDescriptor As IntPtr,   ' PSECURITY_DESCRIPTOR optional
    CurrentSecurityDescriptor As IntPtr,   ' PSECURITY_DESCRIPTOR
    NewSecurityDescriptor As IntPtr,   ' PSECURITY_DESCRIPTOR* out
    ObjectType As IntPtr,   ' GUID* optional
    <MarshalAs(UnmanagedType.U1)> IsDirectoryObject As Boolean,   ' BOOLEAN
    GenericMapping As IntPtr   ' GENERIC_MAPPING*
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function
' ParentDescriptor : PSECURITY_DESCRIPTOR optional
' CurrentSecurityDescriptor : PSECURITY_DESCRIPTOR
' NewSecurityDescriptor : PSECURITY_DESCRIPTOR* out
' ObjectType : GUID* optional
' IsDirectoryObject : BOOLEAN
' GenericMapping : GENERIC_MAPPING*
Declare PtrSafe Function ConvertToAutoInheritPrivateObjectSecurity Lib "advapi32" ( _
    ByVal ParentDescriptor As LongPtr, _
    ByVal CurrentSecurityDescriptor As LongPtr, _
    ByVal NewSecurityDescriptor As LongPtr, _
    ByVal ObjectType As LongPtr, _
    ByVal IsDirectoryObject As Byte, _
    ByVal GenericMapping As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

ConvertToAutoInheritPrivateObjectSecurity = ctypes.windll.advapi32.ConvertToAutoInheritPrivateObjectSecurity
ConvertToAutoInheritPrivateObjectSecurity.restype = wintypes.BOOL
ConvertToAutoInheritPrivateObjectSecurity.argtypes = [
    wintypes.HANDLE,  # ParentDescriptor : PSECURITY_DESCRIPTOR optional
    wintypes.HANDLE,  # CurrentSecurityDescriptor : PSECURITY_DESCRIPTOR
    ctypes.c_void_p,  # NewSecurityDescriptor : PSECURITY_DESCRIPTOR* out
    ctypes.c_void_p,  # ObjectType : GUID* optional
    wintypes.BOOLEAN,  # IsDirectoryObject : BOOLEAN
    ctypes.c_void_p,  # GenericMapping : GENERIC_MAPPING*
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

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

var (
	advapi32 = windows.NewLazySystemDLL("ADVAPI32.dll")
	procConvertToAutoInheritPrivateObjectSecurity = advapi32.NewProc("ConvertToAutoInheritPrivateObjectSecurity")
)

// ParentDescriptor (PSECURITY_DESCRIPTOR optional), CurrentSecurityDescriptor (PSECURITY_DESCRIPTOR), NewSecurityDescriptor (PSECURITY_DESCRIPTOR* out), ObjectType (GUID* optional), IsDirectoryObject (BOOLEAN), GenericMapping (GENERIC_MAPPING*)
r1, _, err := procConvertToAutoInheritPrivateObjectSecurity.Call(
	uintptr(ParentDescriptor),
	uintptr(CurrentSecurityDescriptor),
	uintptr(NewSecurityDescriptor),
	uintptr(ObjectType),
	uintptr(IsDirectoryObject),
	uintptr(GenericMapping),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function ConvertToAutoInheritPrivateObjectSecurity(
  ParentDescriptor: THandle;   // PSECURITY_DESCRIPTOR optional
  CurrentSecurityDescriptor: THandle;   // PSECURITY_DESCRIPTOR
  NewSecurityDescriptor: Pointer;   // PSECURITY_DESCRIPTOR* out
  ObjectType: PGUID;   // GUID* optional
  IsDirectoryObject: ByteBool;   // BOOLEAN
  GenericMapping: Pointer   // GENERIC_MAPPING*
): BOOL; stdcall;
  external 'ADVAPI32.dll' name 'ConvertToAutoInheritPrivateObjectSecurity';
result := DllCall("ADVAPI32\ConvertToAutoInheritPrivateObjectSecurity"
    , "Ptr", ParentDescriptor   ; PSECURITY_DESCRIPTOR optional
    , "Ptr", CurrentSecurityDescriptor   ; PSECURITY_DESCRIPTOR
    , "Ptr", NewSecurityDescriptor   ; PSECURITY_DESCRIPTOR* out
    , "Ptr", ObjectType   ; GUID* optional
    , "Char", IsDirectoryObject   ; BOOLEAN
    , "Ptr", GenericMapping   ; GENERIC_MAPPING*
    , "Int")   ; return: BOOL
●ConvertToAutoInheritPrivateObjectSecurity(ParentDescriptor, CurrentSecurityDescriptor, NewSecurityDescriptor, ObjectType, IsDirectoryObject, GenericMapping) = DLL("ADVAPI32.dll", "bool ConvertToAutoInheritPrivateObjectSecurity(void*, void*, void*, void*, byte, void*)")
# 呼び出し: ConvertToAutoInheritPrivateObjectSecurity(ParentDescriptor, CurrentSecurityDescriptor, NewSecurityDescriptor, ObjectType, IsDirectoryObject, GenericMapping)
# ParentDescriptor : PSECURITY_DESCRIPTOR optional -> "void*"
# CurrentSecurityDescriptor : PSECURITY_DESCRIPTOR -> "void*"
# NewSecurityDescriptor : PSECURITY_DESCRIPTOR* out -> "void*"
# ObjectType : GUID* optional -> "void*"
# IsDirectoryObject : BOOLEAN -> "byte"
# GenericMapping : GENERIC_MAPPING* -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

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

typedef ConvertToAutoInheritPrivateObjectSecurityNative = Int32 Function(Pointer<Void>, Pointer<Void>, Pointer<Void>, Pointer<Void>, Uint8, Pointer<Void>);
typedef ConvertToAutoInheritPrivateObjectSecurityDart = int Function(Pointer<Void>, Pointer<Void>, Pointer<Void>, Pointer<Void>, int, Pointer<Void>);
final ConvertToAutoInheritPrivateObjectSecurity = DynamicLibrary.open('ADVAPI32.dll')
    .lookupFunction<ConvertToAutoInheritPrivateObjectSecurityNative, ConvertToAutoInheritPrivateObjectSecurityDart>('ConvertToAutoInheritPrivateObjectSecurity');
// ParentDescriptor : PSECURITY_DESCRIPTOR optional -> Pointer<Void>
// CurrentSecurityDescriptor : PSECURITY_DESCRIPTOR -> Pointer<Void>
// NewSecurityDescriptor : PSECURITY_DESCRIPTOR* out -> Pointer<Void>
// ObjectType : GUID* optional -> Pointer<Void>
// IsDirectoryObject : BOOLEAN -> Uint8
// GenericMapping : GENERIC_MAPPING* -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function ConvertToAutoInheritPrivateObjectSecurity(
  ParentDescriptor: THandle;   // PSECURITY_DESCRIPTOR optional
  CurrentSecurityDescriptor: THandle;   // PSECURITY_DESCRIPTOR
  NewSecurityDescriptor: Pointer;   // PSECURITY_DESCRIPTOR* out
  ObjectType: PGUID;   // GUID* optional
  IsDirectoryObject: ByteBool;   // BOOLEAN
  GenericMapping: Pointer   // GENERIC_MAPPING*
): BOOL; stdcall;
  external 'ADVAPI32.dll' name 'ConvertToAutoInheritPrivateObjectSecurity';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "ConvertToAutoInheritPrivateObjectSecurity"
  c_ConvertToAutoInheritPrivateObjectSecurity :: Ptr () -> Ptr () -> Ptr () -> Ptr () -> Word8 -> Ptr () -> IO CInt
-- ParentDescriptor : PSECURITY_DESCRIPTOR optional -> Ptr ()
-- CurrentSecurityDescriptor : PSECURITY_DESCRIPTOR -> Ptr ()
-- NewSecurityDescriptor : PSECURITY_DESCRIPTOR* out -> Ptr ()
-- ObjectType : GUID* optional -> Ptr ()
-- IsDirectoryObject : BOOLEAN -> Word8
-- GenericMapping : GENERIC_MAPPING* -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let converttoautoinheritprivateobjectsecurity =
  foreign "ConvertToAutoInheritPrivateObjectSecurity"
    ((ptr void) @-> (ptr void) @-> (ptr void) @-> (ptr void) @-> uint8_t @-> (ptr void) @-> returning int32_t)
(* ParentDescriptor : PSECURITY_DESCRIPTOR optional -> (ptr void) *)
(* CurrentSecurityDescriptor : PSECURITY_DESCRIPTOR -> (ptr void) *)
(* NewSecurityDescriptor : PSECURITY_DESCRIPTOR* out -> (ptr void) *)
(* ObjectType : GUID* optional -> (ptr void) *)
(* IsDirectoryObject : BOOLEAN -> uint8_t *)
(* GenericMapping : GENERIC_MAPPING* -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library advapi32 (t "ADVAPI32.dll"))
(cffi:use-foreign-library advapi32)

(cffi:defcfun ("ConvertToAutoInheritPrivateObjectSecurity" convert-to-auto-inherit-private-object-security :convention :stdcall) :int32
  (parent-descriptor :pointer)   ; PSECURITY_DESCRIPTOR optional
  (current-security-descriptor :pointer)   ; PSECURITY_DESCRIPTOR
  (new-security-descriptor :pointer)   ; PSECURITY_DESCRIPTOR* out
  (object-type :pointer)   ; GUID* optional
  (is-directory-object :uint8)   ; BOOLEAN
  (generic-mapping :pointer))   ; GENERIC_MAPPING*
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $ConvertToAutoInheritPrivateObjectSecurity = Win32::API::More->new('ADVAPI32',
    'BOOL ConvertToAutoInheritPrivateObjectSecurity(HANDLE ParentDescriptor, HANDLE CurrentSecurityDescriptor, HANDLE NewSecurityDescriptor, LPVOID ObjectType, BYTE IsDirectoryObject, LPVOID GenericMapping)');
# my $ret = $ConvertToAutoInheritPrivateObjectSecurity->Call($ParentDescriptor, $CurrentSecurityDescriptor, $NewSecurityDescriptor, $ObjectType, $IsDirectoryObject, $GenericMapping);
# ParentDescriptor : PSECURITY_DESCRIPTOR optional -> HANDLE
# CurrentSecurityDescriptor : PSECURITY_DESCRIPTOR -> HANDLE
# NewSecurityDescriptor : PSECURITY_DESCRIPTOR* out -> HANDLE
# ObjectType : GUID* optional -> LPVOID
# IsDirectoryObject : BOOLEAN -> BYTE
# GenericMapping : GENERIC_MAPPING* -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

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