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絶対形式の SECURITY_DESCRIPTOR 構造体へのポインターです。この関数は、元のセキュリティ記述子を変更することなく、このセキュリティ記述子を自己相対形式に変換したものを作成します。
pSelfRelativeSecurityDescriptorPSECURITY_DESCRIPTORoutoptional自己相対形式のセキュリティ記述子で関数が埋めるバッファーへのポインターです。
lpdwBufferLengthDWORD*inoutpSelfRelativeSD パラメーターが指すバッファーのサイズを指定する変数へのポインターです。バッファーがセキュリティ記述子を格納するのに十分な大きさでない場合、関数は失敗し、この変数に必要な最小サイズを設定します。

戻り値の型: BOOL

公式ドキュメント

絶対形式のセキュリティ記述子をテンプレートとして使用し、自己相対形式のセキュリティ記述子を作成します。

戻り値

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

関数が失敗した場合、戻り値は 0 です。拡張エラー情報を取得するには、 GetLastError を呼び出します。返される可能性のあるコードには、以下のものが含まれますが、これらに限定されません。

戻り値コード/値 説明
ERROR_INSUFFICIENT_BUFFER
0x7A
1 つ以上のバッファーが小さすぎます。

解説(Remarks)

絶対形式のセキュリティ記述子は、情報そのものを格納するのではなく、格納する情報へのポインターを含みます。自己相対形式のセキュリティ記述子は、連続したメモリブロック内に情報を格納します。自己相対形式のセキュリティ記述子では、常に SECURITY_DESCRIPTOR 構造体が情報の先頭となりますが、セキュリティ記述子のその他のコンポーネントは任意の順序でこの構造体の後に続けることができます。各コンポーネントは、メモリアドレスを使用する代わりに、セキュリティ記述子の先頭からのオフセットによって識別されます。この形式は、セキュリティ記述子をフロッピーディスクに保存したり、通信プロトコルを介して送信したりする必要がある場合に役立ちます。

セキュリティ保護されたオブジェクトをさまざまなメディアにコピーするサーバーでは、MakeSelfRelativeSD 関数を使用して絶対セキュリティ記述子から自己相対セキュリティ記述子を作成し、 MakeAbsoluteSD 関数を使用して自己相対セキュリティ記述子から絶対セキュリティ記述子を作成できます。

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

各言語での呼び出し定義

// 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 <MarshalAs(UnmanagedType.Bool)> 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)。
const std = @import("std");

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

typedef MakeSelfRelativeSDNative = Int32 Function(Pointer<Void>, Pointer<Void>, Pointer<Uint32>);
typedef MakeSelfRelativeSDDart = int Function(Pointer<Void>, Pointer<Void>, Pointer<Uint32>);
final MakeSelfRelativeSD = DynamicLibrary.open('ADVAPI32.dll')
    .lookupFunction<MakeSelfRelativeSDNative, MakeSelfRelativeSDDart>('MakeSelfRelativeSD');
// pAbsoluteSecurityDescriptor : PSECURITY_DESCRIPTOR -> Pointer<Void>
// pSelfRelativeSecurityDescriptor : PSECURITY_DESCRIPTOR optional, out -> Pointer<Void>
// lpdwBufferLength : DWORD* in/out -> Pointer<Uint32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function MakeSelfRelativeSD(
  pAbsoluteSecurityDescriptor: THandle;   // PSECURITY_DESCRIPTOR
  pSelfRelativeSecurityDescriptor: THandle;   // PSECURITY_DESCRIPTOR optional, out
  lpdwBufferLength: Pointer   // DWORD* in/out
): BOOL; stdcall;
  external 'ADVAPI32.dll' name 'MakeSelfRelativeSD';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "MakeSelfRelativeSD"
  c_MakeSelfRelativeSD :: Ptr () -> Ptr () -> Ptr Word32 -> IO CInt
-- pAbsoluteSecurityDescriptor : PSECURITY_DESCRIPTOR -> Ptr ()
-- pSelfRelativeSecurityDescriptor : PSECURITY_DESCRIPTOR optional, out -> Ptr ()
-- lpdwBufferLength : DWORD* in/out -> Ptr Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let makeselfrelativesd =
  foreign "MakeSelfRelativeSD"
    ((ptr void) @-> (ptr void) @-> (ptr uint32_t) @-> returning int32_t)
(* pAbsoluteSecurityDescriptor : PSECURITY_DESCRIPTOR -> (ptr void) *)
(* pSelfRelativeSecurityDescriptor : PSECURITY_DESCRIPTOR optional, out -> (ptr void) *)
(* lpdwBufferLength : DWORD* in/out -> (ptr uint32_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library advapi32 (t "ADVAPI32.dll"))
(cffi:use-foreign-library advapi32)

(cffi:defcfun ("MakeSelfRelativeSD" make-self-relative-sd :convention :stdcall) :int32
  (p-absolute-security-descriptor :pointer)   ; PSECURITY_DESCRIPTOR
  (p-self-relative-security-descriptor :pointer)   ; PSECURITY_DESCRIPTOR optional, out
  (lpdw-buffer-length :pointer))   ; DWORD* in/out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $MakeSelfRelativeSD = Win32::API::More->new('ADVAPI32',
    'BOOL MakeSelfRelativeSD(HANDLE pAbsoluteSecurityDescriptor, HANDLE pSelfRelativeSecurityDescriptor, LPVOID lpdwBufferLength)');
# my $ret = $MakeSelfRelativeSD->Call($pAbsoluteSecurityDescriptor, $pSelfRelativeSecurityDescriptor, $lpdwBufferLength);
# pAbsoluteSecurityDescriptor : PSECURITY_DESCRIPTOR -> HANDLE
# pSelfRelativeSecurityDescriptor : PSECURITY_DESCRIPTOR optional, out -> HANDLE
# lpdwBufferLength : DWORD* in/out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

公式の関連項目