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

MakeSelfRelativeSD

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

シグネチャ

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

BOOL MakeSelfRelativeSD(
    PSECURITY_DESCRIPTOR pAbsoluteSecurityDescriptor,
    PSECURITY_DESCRIPTOR pSelfRelativeSecurityDescriptor,   // optional
    DWORD* lpdwBufferLength
);

パラメーター

名前方向
pAbsoluteSecurityDescriptorPSECURITY_DESCRIPTORin
pSelfRelativeSecurityDescriptorPSECURITY_DESCRIPTORoutoptional
lpdwBufferLengthDWORD*inout

戻り値の型: BOOL

各言語での呼び出し定義

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

BOOL MakeSelfRelativeSD(
    PSECURITY_DESCRIPTOR pAbsoluteSecurityDescriptor,
    PSECURITY_DESCRIPTOR pSelfRelativeSecurityDescriptor,   // optional
    DWORD* lpdwBufferLength
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("ADVAPI32.dll", SetLastError = true, ExactSpelling = true)]
static extern bool MakeSelfRelativeSD(
    IntPtr pAbsoluteSecurityDescriptor,   // PSECURITY_DESCRIPTOR
    IntPtr pSelfRelativeSecurityDescriptor,   // PSECURITY_DESCRIPTOR optional, out
    ref uint lpdwBufferLength   // DWORD* in/out
);
<DllImport("ADVAPI32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function MakeSelfRelativeSD(
    pAbsoluteSecurityDescriptor As IntPtr,   ' PSECURITY_DESCRIPTOR
    pSelfRelativeSecurityDescriptor As IntPtr,   ' PSECURITY_DESCRIPTOR optional, out
    ByRef lpdwBufferLength As UInteger   ' DWORD* in/out
) As Boolean
End Function
' pAbsoluteSecurityDescriptor : PSECURITY_DESCRIPTOR
' pSelfRelativeSecurityDescriptor : PSECURITY_DESCRIPTOR optional, out
' lpdwBufferLength : DWORD* in/out
Declare PtrSafe Function MakeSelfRelativeSD Lib "advapi32" ( _
    ByVal pAbsoluteSecurityDescriptor As LongPtr, _
    ByVal pSelfRelativeSecurityDescriptor As LongPtr, _
    ByRef lpdwBufferLength As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

MakeSelfRelativeSD = ctypes.windll.advapi32.MakeSelfRelativeSD
MakeSelfRelativeSD.restype = wintypes.BOOL
MakeSelfRelativeSD.argtypes = [
    wintypes.HANDLE,  # pAbsoluteSecurityDescriptor : PSECURITY_DESCRIPTOR
    wintypes.HANDLE,  # pSelfRelativeSecurityDescriptor : PSECURITY_DESCRIPTOR optional, out
    ctypes.POINTER(wintypes.DWORD),  # lpdwBufferLength : DWORD* in/out
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

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

var (
	advapi32 = windows.NewLazySystemDLL("ADVAPI32.dll")
	procMakeSelfRelativeSD = advapi32.NewProc("MakeSelfRelativeSD")
)

// pAbsoluteSecurityDescriptor (PSECURITY_DESCRIPTOR), pSelfRelativeSecurityDescriptor (PSECURITY_DESCRIPTOR optional, out), lpdwBufferLength (DWORD* in/out)
r1, _, err := procMakeSelfRelativeSD.Call(
	uintptr(pAbsoluteSecurityDescriptor),
	uintptr(pSelfRelativeSecurityDescriptor),
	uintptr(lpdwBufferLength),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function MakeSelfRelativeSD(
  pAbsoluteSecurityDescriptor: THandle;   // PSECURITY_DESCRIPTOR
  pSelfRelativeSecurityDescriptor: THandle;   // PSECURITY_DESCRIPTOR optional, out
  lpdwBufferLength: Pointer   // DWORD* in/out
): BOOL; stdcall;
  external 'ADVAPI32.dll' name 'MakeSelfRelativeSD';
result := DllCall("ADVAPI32\MakeSelfRelativeSD"
    , "Ptr", pAbsoluteSecurityDescriptor   ; PSECURITY_DESCRIPTOR
    , "Ptr", pSelfRelativeSecurityDescriptor   ; PSECURITY_DESCRIPTOR optional, out
    , "Ptr", lpdwBufferLength   ; DWORD* in/out
    , "Int")   ; return: BOOL
●MakeSelfRelativeSD(pAbsoluteSecurityDescriptor, pSelfRelativeSecurityDescriptor, lpdwBufferLength) = DLL("ADVAPI32.dll", "bool MakeSelfRelativeSD(void*, void*, void*)")
# 呼び出し: MakeSelfRelativeSD(pAbsoluteSecurityDescriptor, pSelfRelativeSecurityDescriptor, lpdwBufferLength)
# pAbsoluteSecurityDescriptor : PSECURITY_DESCRIPTOR -> "void*"
# pSelfRelativeSecurityDescriptor : PSECURITY_DESCRIPTOR optional, out -> "void*"
# lpdwBufferLength : DWORD* in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。