CreatePrivateObjectSecurity
関数シグネチャ
// ADVAPI32.dll
#include <windows.h>
BOOL CreatePrivateObjectSecurity(
PSECURITY_DESCRIPTOR ParentDescriptor, // optional
PSECURITY_DESCRIPTOR CreatorDescriptor, // optional
PSECURITY_DESCRIPTOR* NewDescriptor,
BOOL IsDirectoryObject,
HANDLE Token, // optional
GENERIC_MAPPING* GenericMapping
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| ParentDescriptor | PSECURITY_DESCRIPTOR | inoptional | 新しいオブジェクトが作成される親ディレクトリのセキュリティ記述子へのポインターです。親ディレクトリが存在しない場合、このパラメーターには NULL を指定できます。 |
| CreatorDescriptor | PSECURITY_DESCRIPTOR | inoptional | オブジェクトの作成者が提供するセキュリティ記述子へのポインターです。オブジェクトの作成者が新しいオブジェクトのセキュリティ情報を明示的に渡さない場合、このパラメーターには NULL を指定することを想定しています。 |
| NewDescriptor | PSECURITY_DESCRIPTOR* | out | 新しく割り当てられた自己相対形式のセキュリティ記述子へのポインターを受け取る変数へのポインターです。呼び出し元は、このセキュリティ記述子を解放するために DestroyPrivateObjectSecurity 関数を呼び出す必要があります。 |
| IsDirectoryObject | BOOL | in | 新しいオブジェクトがコンテナーであるかどうかを指定します。値が TRUE の場合、オブジェクトはディレクトリのように他のオブジェクトを含みます。 |
| Token | HANDLE | inoptional | オブジェクトの作成元となるクライアントプロセスのアクセストークンへのハンドルです。これが偽装トークンである場合、SecurityIdentification レベル以上である必要があります。SecurityIdentification 偽装レベルの詳細については、 SECURITY_IMPERSONATION_LEVEL 列挙型を参照してください。 クライアントトークンは、既定の所有者、プライマリグループ、随意アクセス制御リストなど、新しいオブジェクトの既定のセキュリティ情報を取得するために使用されます。トークンは TOKEN_QUERY アクセスで開かれている必要があります。 次のすべての条件が満たされる場合、ハンドルは TOKEN_QUERY アクセスに加えて TOKEN_DUPLICATE アクセスでも開かれている必要があります。
|
| GenericMapping | GENERIC_MAPPING* | in | 各汎用アクセス権からオブジェクトの個別アクセス権へのマッピングを指定する GENERIC_MAPPING 構造体へのポインターです。 |
戻り値の型: BOOL
公式ドキュメント
新しいプライベートオブジェクトのために、自己相対形式のセキュリティ記述子を割り当てて初期化します。保護されたサーバーは、新しいプライベートオブジェクトを作成するときにこの関数を呼び出します。
戻り値
関数が成功した場合、関数は 0 以外の値を返します。
関数が失敗した場合は 0 を返します。拡張エラー情報を取得するには、 GetLastError を呼び出してください。
解説(Remarks)
CreatorDescriptor パラメーターで指定された SECURITY_DESCRIPTOR にシステムアクセス制御リスト (SACL) が指定されている場合、Token パラメーターでは SE_SECURITY_NAME 特権が有効になっている必要があります。CreatePrivateObjectSecurity 関数はこの特権をチェックし、その処理中に監査を生成する場合があります。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// ADVAPI32.dll
#include <windows.h>
BOOL CreatePrivateObjectSecurity(
PSECURITY_DESCRIPTOR ParentDescriptor, // optional
PSECURITY_DESCRIPTOR CreatorDescriptor, // optional
PSECURITY_DESCRIPTOR* NewDescriptor,
BOOL IsDirectoryObject,
HANDLE Token, // optional
GENERIC_MAPPING* GenericMapping
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("ADVAPI32.dll", SetLastError = true, ExactSpelling = true)]
static extern bool CreatePrivateObjectSecurity(
IntPtr ParentDescriptor, // PSECURITY_DESCRIPTOR optional
IntPtr CreatorDescriptor, // PSECURITY_DESCRIPTOR optional
IntPtr NewDescriptor, // PSECURITY_DESCRIPTOR* out
bool IsDirectoryObject, // BOOL
IntPtr Token, // HANDLE optional
IntPtr GenericMapping // GENERIC_MAPPING*
);<DllImport("ADVAPI32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function CreatePrivateObjectSecurity(
ParentDescriptor As IntPtr, ' PSECURITY_DESCRIPTOR optional
CreatorDescriptor As IntPtr, ' PSECURITY_DESCRIPTOR optional
NewDescriptor As IntPtr, ' PSECURITY_DESCRIPTOR* out
IsDirectoryObject As Boolean, ' BOOL
Token As IntPtr, ' HANDLE optional
GenericMapping As IntPtr ' GENERIC_MAPPING*
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function' ParentDescriptor : PSECURITY_DESCRIPTOR optional
' CreatorDescriptor : PSECURITY_DESCRIPTOR optional
' NewDescriptor : PSECURITY_DESCRIPTOR* out
' IsDirectoryObject : BOOL
' Token : HANDLE optional
' GenericMapping : GENERIC_MAPPING*
Declare PtrSafe Function CreatePrivateObjectSecurity Lib "advapi32" ( _
ByVal ParentDescriptor As LongPtr, _
ByVal CreatorDescriptor As LongPtr, _
ByVal NewDescriptor As LongPtr, _
ByVal IsDirectoryObject As Long, _
ByVal Token As LongPtr, _
ByVal GenericMapping As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
CreatePrivateObjectSecurity = ctypes.windll.advapi32.CreatePrivateObjectSecurity
CreatePrivateObjectSecurity.restype = wintypes.BOOL
CreatePrivateObjectSecurity.argtypes = [
wintypes.HANDLE, # ParentDescriptor : PSECURITY_DESCRIPTOR optional
wintypes.HANDLE, # CreatorDescriptor : PSECURITY_DESCRIPTOR optional
ctypes.c_void_p, # NewDescriptor : PSECURITY_DESCRIPTOR* out
wintypes.BOOL, # IsDirectoryObject : BOOL
wintypes.HANDLE, # Token : HANDLE optional
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')
CreatePrivateObjectSecurity = Fiddle::Function.new(
lib['CreatePrivateObjectSecurity'],
[
Fiddle::TYPE_VOIDP, # ParentDescriptor : PSECURITY_DESCRIPTOR optional
Fiddle::TYPE_VOIDP, # CreatorDescriptor : PSECURITY_DESCRIPTOR optional
Fiddle::TYPE_VOIDP, # NewDescriptor : PSECURITY_DESCRIPTOR* out
Fiddle::TYPE_INT, # IsDirectoryObject : BOOL
Fiddle::TYPE_VOIDP, # Token : HANDLE optional
Fiddle::TYPE_VOIDP, # GenericMapping : GENERIC_MAPPING*
],
Fiddle::TYPE_INT)#[link(name = "advapi32")]
extern "system" {
fn CreatePrivateObjectSecurity(
ParentDescriptor: *mut core::ffi::c_void, // PSECURITY_DESCRIPTOR optional
CreatorDescriptor: *mut core::ffi::c_void, // PSECURITY_DESCRIPTOR optional
NewDescriptor: *mut *mut core::ffi::c_void, // PSECURITY_DESCRIPTOR* out
IsDirectoryObject: i32, // BOOL
Token: *mut core::ffi::c_void, // HANDLE optional
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 CreatePrivateObjectSecurity(IntPtr ParentDescriptor, IntPtr CreatorDescriptor, IntPtr NewDescriptor, bool IsDirectoryObject, IntPtr Token, IntPtr GenericMapping);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ADVAPI32_CreatePrivateObjectSecurity' -Namespace Win32 -PassThru
# $api::CreatePrivateObjectSecurity(ParentDescriptor, CreatorDescriptor, NewDescriptor, IsDirectoryObject, Token, GenericMapping)#uselib "ADVAPI32.dll"
#func global CreatePrivateObjectSecurity "CreatePrivateObjectSecurity" sptr, sptr, sptr, sptr, sptr, sptr
; CreatePrivateObjectSecurity ParentDescriptor, CreatorDescriptor, NewDescriptor, IsDirectoryObject, Token, varptr(GenericMapping) ; 戻り値は stat
; ParentDescriptor : PSECURITY_DESCRIPTOR optional -> "sptr"
; CreatorDescriptor : PSECURITY_DESCRIPTOR optional -> "sptr"
; NewDescriptor : PSECURITY_DESCRIPTOR* out -> "sptr"
; IsDirectoryObject : BOOL -> "sptr"
; Token : HANDLE optional -> "sptr"
; GenericMapping : GENERIC_MAPPING* -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "ADVAPI32.dll" #cfunc global CreatePrivateObjectSecurity "CreatePrivateObjectSecurity" sptr, sptr, sptr, int, sptr, var ; res = CreatePrivateObjectSecurity(ParentDescriptor, CreatorDescriptor, NewDescriptor, IsDirectoryObject, Token, GenericMapping) ; ParentDescriptor : PSECURITY_DESCRIPTOR optional -> "sptr" ; CreatorDescriptor : PSECURITY_DESCRIPTOR optional -> "sptr" ; NewDescriptor : PSECURITY_DESCRIPTOR* out -> "sptr" ; IsDirectoryObject : BOOL -> "int" ; Token : HANDLE optional -> "sptr" ; GenericMapping : GENERIC_MAPPING* -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "ADVAPI32.dll" #cfunc global CreatePrivateObjectSecurity "CreatePrivateObjectSecurity" sptr, sptr, sptr, int, sptr, sptr ; res = CreatePrivateObjectSecurity(ParentDescriptor, CreatorDescriptor, NewDescriptor, IsDirectoryObject, Token, varptr(GenericMapping)) ; ParentDescriptor : PSECURITY_DESCRIPTOR optional -> "sptr" ; CreatorDescriptor : PSECURITY_DESCRIPTOR optional -> "sptr" ; NewDescriptor : PSECURITY_DESCRIPTOR* out -> "sptr" ; IsDirectoryObject : BOOL -> "int" ; Token : HANDLE optional -> "sptr" ; GenericMapping : GENERIC_MAPPING* -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
; BOOL CreatePrivateObjectSecurity(PSECURITY_DESCRIPTOR ParentDescriptor, PSECURITY_DESCRIPTOR CreatorDescriptor, PSECURITY_DESCRIPTOR* NewDescriptor, BOOL IsDirectoryObject, HANDLE Token, GENERIC_MAPPING* GenericMapping) #uselib "ADVAPI32.dll" #cfunc global CreatePrivateObjectSecurity "CreatePrivateObjectSecurity" intptr, intptr, intptr, int, intptr, var ; res = CreatePrivateObjectSecurity(ParentDescriptor, CreatorDescriptor, NewDescriptor, IsDirectoryObject, Token, GenericMapping) ; ParentDescriptor : PSECURITY_DESCRIPTOR optional -> "intptr" ; CreatorDescriptor : PSECURITY_DESCRIPTOR optional -> "intptr" ; NewDescriptor : PSECURITY_DESCRIPTOR* out -> "intptr" ; IsDirectoryObject : BOOL -> "int" ; Token : HANDLE optional -> "intptr" ; GenericMapping : GENERIC_MAPPING* -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; BOOL CreatePrivateObjectSecurity(PSECURITY_DESCRIPTOR ParentDescriptor, PSECURITY_DESCRIPTOR CreatorDescriptor, PSECURITY_DESCRIPTOR* NewDescriptor, BOOL IsDirectoryObject, HANDLE Token, GENERIC_MAPPING* GenericMapping) #uselib "ADVAPI32.dll" #cfunc global CreatePrivateObjectSecurity "CreatePrivateObjectSecurity" intptr, intptr, intptr, int, intptr, intptr ; res = CreatePrivateObjectSecurity(ParentDescriptor, CreatorDescriptor, NewDescriptor, IsDirectoryObject, Token, varptr(GenericMapping)) ; ParentDescriptor : PSECURITY_DESCRIPTOR optional -> "intptr" ; CreatorDescriptor : PSECURITY_DESCRIPTOR optional -> "intptr" ; NewDescriptor : PSECURITY_DESCRIPTOR* out -> "intptr" ; IsDirectoryObject : BOOL -> "int" ; Token : HANDLE optional -> "intptr" ; GenericMapping : GENERIC_MAPPING* -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
advapi32 = windows.NewLazySystemDLL("ADVAPI32.dll")
procCreatePrivateObjectSecurity = advapi32.NewProc("CreatePrivateObjectSecurity")
)
// ParentDescriptor (PSECURITY_DESCRIPTOR optional), CreatorDescriptor (PSECURITY_DESCRIPTOR optional), NewDescriptor (PSECURITY_DESCRIPTOR* out), IsDirectoryObject (BOOL), Token (HANDLE optional), GenericMapping (GENERIC_MAPPING*)
r1, _, err := procCreatePrivateObjectSecurity.Call(
uintptr(ParentDescriptor),
uintptr(CreatorDescriptor),
uintptr(NewDescriptor),
uintptr(IsDirectoryObject),
uintptr(Token),
uintptr(GenericMapping),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction CreatePrivateObjectSecurity(
ParentDescriptor: THandle; // PSECURITY_DESCRIPTOR optional
CreatorDescriptor: THandle; // PSECURITY_DESCRIPTOR optional
NewDescriptor: Pointer; // PSECURITY_DESCRIPTOR* out
IsDirectoryObject: BOOL; // BOOL
Token: THandle; // HANDLE optional
GenericMapping: Pointer // GENERIC_MAPPING*
): BOOL; stdcall;
external 'ADVAPI32.dll' name 'CreatePrivateObjectSecurity';result := DllCall("ADVAPI32\CreatePrivateObjectSecurity"
, "Ptr", ParentDescriptor ; PSECURITY_DESCRIPTOR optional
, "Ptr", CreatorDescriptor ; PSECURITY_DESCRIPTOR optional
, "Ptr", NewDescriptor ; PSECURITY_DESCRIPTOR* out
, "Int", IsDirectoryObject ; BOOL
, "Ptr", Token ; HANDLE optional
, "Ptr", GenericMapping ; GENERIC_MAPPING*
, "Int") ; return: BOOL●CreatePrivateObjectSecurity(ParentDescriptor, CreatorDescriptor, NewDescriptor, IsDirectoryObject, Token, GenericMapping) = DLL("ADVAPI32.dll", "bool CreatePrivateObjectSecurity(void*, void*, void*, bool, void*, void*)")
# 呼び出し: CreatePrivateObjectSecurity(ParentDescriptor, CreatorDescriptor, NewDescriptor, IsDirectoryObject, Token, GenericMapping)
# ParentDescriptor : PSECURITY_DESCRIPTOR optional -> "void*"
# CreatorDescriptor : PSECURITY_DESCRIPTOR optional -> "void*"
# NewDescriptor : PSECURITY_DESCRIPTOR* out -> "void*"
# IsDirectoryObject : BOOL -> "bool"
# Token : HANDLE optional -> "void*"
# GenericMapping : GENERIC_MAPPING* -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "advapi32" fn CreatePrivateObjectSecurity(
ParentDescriptor: ?*anyopaque, // PSECURITY_DESCRIPTOR optional
CreatorDescriptor: ?*anyopaque, // PSECURITY_DESCRIPTOR optional
NewDescriptor: ?*anyopaque, // PSECURITY_DESCRIPTOR* out
IsDirectoryObject: i32, // BOOL
Token: ?*anyopaque, // HANDLE optional
GenericMapping: [*c]GENERIC_MAPPING // GENERIC_MAPPING*
) callconv(std.os.windows.WINAPI) i32;proc CreatePrivateObjectSecurity(
ParentDescriptor: pointer, # PSECURITY_DESCRIPTOR optional
CreatorDescriptor: pointer, # PSECURITY_DESCRIPTOR optional
NewDescriptor: pointer, # PSECURITY_DESCRIPTOR* out
IsDirectoryObject: int32, # BOOL
Token: pointer, # HANDLE optional
GenericMapping: ptr GENERIC_MAPPING # GENERIC_MAPPING*
): int32 {.importc: "CreatePrivateObjectSecurity", stdcall, dynlib: "ADVAPI32.dll".}pragma(lib, "advapi32");
extern(Windows)
int CreatePrivateObjectSecurity(
void* ParentDescriptor, // PSECURITY_DESCRIPTOR optional
void* CreatorDescriptor, // PSECURITY_DESCRIPTOR optional
void* NewDescriptor, // PSECURITY_DESCRIPTOR* out
int IsDirectoryObject, // BOOL
void* Token, // HANDLE optional
GENERIC_MAPPING* GenericMapping // GENERIC_MAPPING*
);ccall((:CreatePrivateObjectSecurity, "ADVAPI32.dll"), stdcall, Int32,
(Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cvoid}, Int32, Ptr{Cvoid}, Ptr{GENERIC_MAPPING}),
ParentDescriptor, CreatorDescriptor, NewDescriptor, IsDirectoryObject, Token, GenericMapping)
# ParentDescriptor : PSECURITY_DESCRIPTOR optional -> Ptr{Cvoid}
# CreatorDescriptor : PSECURITY_DESCRIPTOR optional -> Ptr{Cvoid}
# NewDescriptor : PSECURITY_DESCRIPTOR* out -> Ptr{Cvoid}
# IsDirectoryObject : BOOL -> Int32
# Token : HANDLE optional -> Ptr{Cvoid}
# GenericMapping : GENERIC_MAPPING* -> Ptr{GENERIC_MAPPING}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t CreatePrivateObjectSecurity(
void* ParentDescriptor,
void* CreatorDescriptor,
void* NewDescriptor,
int32_t IsDirectoryObject,
void* Token,
void* GenericMapping);
]]
local advapi32 = ffi.load("advapi32")
-- advapi32.CreatePrivateObjectSecurity(ParentDescriptor, CreatorDescriptor, NewDescriptor, IsDirectoryObject, Token, GenericMapping)
-- ParentDescriptor : PSECURITY_DESCRIPTOR optional
-- CreatorDescriptor : PSECURITY_DESCRIPTOR optional
-- NewDescriptor : PSECURITY_DESCRIPTOR* out
-- IsDirectoryObject : BOOL
-- Token : HANDLE optional
-- GenericMapping : GENERIC_MAPPING*
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('ADVAPI32.dll');
const CreatePrivateObjectSecurity = lib.func('__stdcall', 'CreatePrivateObjectSecurity', 'int32_t', ['void *', 'void *', 'void *', 'int32_t', 'void *', 'void *']);
// CreatePrivateObjectSecurity(ParentDescriptor, CreatorDescriptor, NewDescriptor, IsDirectoryObject, Token, GenericMapping)
// ParentDescriptor : PSECURITY_DESCRIPTOR optional -> 'void *'
// CreatorDescriptor : PSECURITY_DESCRIPTOR optional -> 'void *'
// NewDescriptor : PSECURITY_DESCRIPTOR* out -> 'void *'
// IsDirectoryObject : BOOL -> 'int32_t'
// Token : HANDLE optional -> 'void *'
// GenericMapping : GENERIC_MAPPING* -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("ADVAPI32.dll", {
CreatePrivateObjectSecurity: { parameters: ["pointer", "pointer", "pointer", "i32", "pointer", "pointer"], result: "i32" },
});
// lib.symbols.CreatePrivateObjectSecurity(ParentDescriptor, CreatorDescriptor, NewDescriptor, IsDirectoryObject, Token, GenericMapping)
// ParentDescriptor : PSECURITY_DESCRIPTOR optional -> "pointer"
// CreatorDescriptor : PSECURITY_DESCRIPTOR optional -> "pointer"
// NewDescriptor : PSECURITY_DESCRIPTOR* out -> "pointer"
// IsDirectoryObject : BOOL -> "i32"
// Token : HANDLE optional -> "pointer"
// GenericMapping : GENERIC_MAPPING* -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t CreatePrivateObjectSecurity(
void* ParentDescriptor,
void* CreatorDescriptor,
void* NewDescriptor,
int32_t IsDirectoryObject,
void* Token,
void* GenericMapping);
C, "ADVAPI32.dll");
// $ffi->CreatePrivateObjectSecurity(ParentDescriptor, CreatorDescriptor, NewDescriptor, IsDirectoryObject, Token, GenericMapping);
// ParentDescriptor : PSECURITY_DESCRIPTOR optional
// CreatorDescriptor : PSECURITY_DESCRIPTOR optional
// NewDescriptor : PSECURITY_DESCRIPTOR* out
// IsDirectoryObject : BOOL
// Token : HANDLE optional
// 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 CreatePrivateObjectSecurity(
Pointer ParentDescriptor, // PSECURITY_DESCRIPTOR optional
Pointer CreatorDescriptor, // PSECURITY_DESCRIPTOR optional
Pointer NewDescriptor, // PSECURITY_DESCRIPTOR* out
boolean IsDirectoryObject, // BOOL
Pointer Token, // HANDLE optional
Pointer GenericMapping // GENERIC_MAPPING*
);
}@[Link("advapi32")]
lib LibADVAPI32
fun CreatePrivateObjectSecurity = CreatePrivateObjectSecurity(
ParentDescriptor : Void*, # PSECURITY_DESCRIPTOR optional
CreatorDescriptor : Void*, # PSECURITY_DESCRIPTOR optional
NewDescriptor : Void*, # PSECURITY_DESCRIPTOR* out
IsDirectoryObject : Int32, # BOOL
Token : Void*, # HANDLE optional
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 CreatePrivateObjectSecurityNative = Int32 Function(Pointer<Void>, Pointer<Void>, Pointer<Void>, Int32, Pointer<Void>, Pointer<Void>);
typedef CreatePrivateObjectSecurityDart = int Function(Pointer<Void>, Pointer<Void>, Pointer<Void>, int, Pointer<Void>, Pointer<Void>);
final CreatePrivateObjectSecurity = DynamicLibrary.open('ADVAPI32.dll')
.lookupFunction<CreatePrivateObjectSecurityNative, CreatePrivateObjectSecurityDart>('CreatePrivateObjectSecurity');
// ParentDescriptor : PSECURITY_DESCRIPTOR optional -> Pointer<Void>
// CreatorDescriptor : PSECURITY_DESCRIPTOR optional -> Pointer<Void>
// NewDescriptor : PSECURITY_DESCRIPTOR* out -> Pointer<Void>
// IsDirectoryObject : BOOL -> Int32
// Token : HANDLE optional -> Pointer<Void>
// GenericMapping : GENERIC_MAPPING* -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function CreatePrivateObjectSecurity(
ParentDescriptor: THandle; // PSECURITY_DESCRIPTOR optional
CreatorDescriptor: THandle; // PSECURITY_DESCRIPTOR optional
NewDescriptor: Pointer; // PSECURITY_DESCRIPTOR* out
IsDirectoryObject: BOOL; // BOOL
Token: THandle; // HANDLE optional
GenericMapping: Pointer // GENERIC_MAPPING*
): BOOL; stdcall;
external 'ADVAPI32.dll' name 'CreatePrivateObjectSecurity';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "CreatePrivateObjectSecurity"
c_CreatePrivateObjectSecurity :: Ptr () -> Ptr () -> Ptr () -> CInt -> Ptr () -> Ptr () -> IO CInt
-- ParentDescriptor : PSECURITY_DESCRIPTOR optional -> Ptr ()
-- CreatorDescriptor : PSECURITY_DESCRIPTOR optional -> Ptr ()
-- NewDescriptor : PSECURITY_DESCRIPTOR* out -> Ptr ()
-- IsDirectoryObject : BOOL -> CInt
-- Token : HANDLE optional -> Ptr ()
-- GenericMapping : GENERIC_MAPPING* -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let createprivateobjectsecurity =
foreign "CreatePrivateObjectSecurity"
((ptr void) @-> (ptr void) @-> (ptr void) @-> int32_t @-> (ptr void) @-> (ptr void) @-> returning int32_t)
(* ParentDescriptor : PSECURITY_DESCRIPTOR optional -> (ptr void) *)
(* CreatorDescriptor : PSECURITY_DESCRIPTOR optional -> (ptr void) *)
(* NewDescriptor : PSECURITY_DESCRIPTOR* out -> (ptr void) *)
(* IsDirectoryObject : BOOL -> int32_t *)
(* Token : HANDLE optional -> (ptr void) *)
(* 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 ("CreatePrivateObjectSecurity" create-private-object-security :convention :stdcall) :int32
(parent-descriptor :pointer) ; PSECURITY_DESCRIPTOR optional
(creator-descriptor :pointer) ; PSECURITY_DESCRIPTOR optional
(new-descriptor :pointer) ; PSECURITY_DESCRIPTOR* out
(is-directory-object :int32) ; BOOL
(token :pointer) ; HANDLE optional
(generic-mapping :pointer)) ; GENERIC_MAPPING*
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $CreatePrivateObjectSecurity = Win32::API::More->new('ADVAPI32',
'BOOL CreatePrivateObjectSecurity(HANDLE ParentDescriptor, HANDLE CreatorDescriptor, HANDLE NewDescriptor, BOOL IsDirectoryObject, HANDLE Token, LPVOID GenericMapping)');
# my $ret = $CreatePrivateObjectSecurity->Call($ParentDescriptor, $CreatorDescriptor, $NewDescriptor, $IsDirectoryObject, $Token, $GenericMapping);
# ParentDescriptor : PSECURITY_DESCRIPTOR optional -> HANDLE
# CreatorDescriptor : PSECURITY_DESCRIPTOR optional -> HANDLE
# NewDescriptor : PSECURITY_DESCRIPTOR* out -> HANDLE
# IsDirectoryObject : BOOL -> BOOL
# Token : HANDLE optional -> HANDLE
# GenericMapping : GENERIC_MAPPING* -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
- f CreatePrivateObjectSecurityEx — オブジェクトタイプと自動継承を指定しセキュリティ記述子を作成する。
- f DestroyPrivateObjectSecurity — プライベートオブジェクトのセキュリティ記述子を解放する。
- f GetPrivateObjectSecurity — プライベートオブジェクトのセキュリティ情報を取得する。
- f GetTokenInformation — アクセストークンの指定種別の情報を取得する。
- f OpenProcessToken — プロセスに関連付けられたアクセストークンを開く。
- s SECURITY_DESCRIPTOR
- e SECURITY_IMPERSONATION_LEVEL
- f SetPrivateObjectSecurity — プライベートオブジェクトのセキュリティ記述子を変更し更新する。