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

CreatePrivateObjectSecurity

関数
親と作成者の記述子からオブジェクト用セキュリティ記述子を作成する。
DLLADVAPI32.dll呼出規約winapiSetLastErrorあり対応OSWindows XP 以降

シグネチャ

// 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
);

パラメーター

名前方向
ParentDescriptorPSECURITY_DESCRIPTORinoptional
CreatorDescriptorPSECURITY_DESCRIPTORinoptional
NewDescriptorPSECURITY_DESCRIPTOR*out
IsDirectoryObjectBOOLin
TokenHANDLEinoptional
GenericMappingGENERIC_MAPPING*in

戻り値の型: BOOL

各言語での呼び出し定義

// 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 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 方式にも切替可。
出力引数:
; 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 方式にも切替可。
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   // BOOL
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';
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)。