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

RtlNormalizeSecurityDescriptor

関数
セキュリティ記述子を正規化された自己相対形式へ変換する。
DLLntdll.dll呼出規約winapi

シグネチャ

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

BOOLEAN RtlNormalizeSecurityDescriptor(
    PSECURITY_DESCRIPTOR* SecurityDescriptor,
    DWORD SecurityDescriptorLength,
    PSECURITY_DESCRIPTOR* NewSecurityDescriptor,   // optional
    DWORD* NewSecurityDescriptorLength,   // optional
    BOOLEAN CheckOnly
);

パラメーター

名前方向
SecurityDescriptorPSECURITY_DESCRIPTOR*inout
SecurityDescriptorLengthDWORDin
NewSecurityDescriptorPSECURITY_DESCRIPTOR*outoptional
NewSecurityDescriptorLengthDWORD*outoptional
CheckOnlyBOOLEANin

戻り値の型: BOOLEAN

各言語での呼び出し定義

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

BOOLEAN RtlNormalizeSecurityDescriptor(
    PSECURITY_DESCRIPTOR* SecurityDescriptor,
    DWORD SecurityDescriptorLength,
    PSECURITY_DESCRIPTOR* NewSecurityDescriptor,   // optional
    DWORD* NewSecurityDescriptorLength,   // optional
    BOOLEAN CheckOnly
);
[DllImport("ntdll.dll", ExactSpelling = true)]
static extern byte RtlNormalizeSecurityDescriptor(
    IntPtr SecurityDescriptor,   // PSECURITY_DESCRIPTOR* in/out
    uint SecurityDescriptorLength,   // DWORD
    IntPtr NewSecurityDescriptor,   // PSECURITY_DESCRIPTOR* optional, out
    IntPtr NewSecurityDescriptorLength,   // DWORD* optional, out
    [MarshalAs(UnmanagedType.U1)] bool CheckOnly   // BOOLEAN
);
<DllImport("ntdll.dll", ExactSpelling:=True)>
Public Shared Function RtlNormalizeSecurityDescriptor(
    SecurityDescriptor As IntPtr,   ' PSECURITY_DESCRIPTOR* in/out
    SecurityDescriptorLength As UInteger,   ' DWORD
    NewSecurityDescriptor As IntPtr,   ' PSECURITY_DESCRIPTOR* optional, out
    NewSecurityDescriptorLength As IntPtr,   ' DWORD* optional, out
    <MarshalAs(UnmanagedType.U1)> CheckOnly As Boolean   ' BOOLEAN
) As Byte
End Function
' SecurityDescriptor : PSECURITY_DESCRIPTOR* in/out
' SecurityDescriptorLength : DWORD
' NewSecurityDescriptor : PSECURITY_DESCRIPTOR* optional, out
' NewSecurityDescriptorLength : DWORD* optional, out
' CheckOnly : BOOLEAN
Declare PtrSafe Function RtlNormalizeSecurityDescriptor Lib "ntdll" ( _
    ByVal SecurityDescriptor As LongPtr, _
    ByVal SecurityDescriptorLength As Long, _
    ByVal NewSecurityDescriptor As LongPtr, _
    ByVal NewSecurityDescriptorLength As LongPtr, _
    ByVal CheckOnly As Byte) As Byte
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

RtlNormalizeSecurityDescriptor = ctypes.windll.ntdll.RtlNormalizeSecurityDescriptor
RtlNormalizeSecurityDescriptor.restype = ctypes.c_byte
RtlNormalizeSecurityDescriptor.argtypes = [
    ctypes.c_void_p,  # SecurityDescriptor : PSECURITY_DESCRIPTOR* in/out
    wintypes.DWORD,  # SecurityDescriptorLength : DWORD
    ctypes.c_void_p,  # NewSecurityDescriptor : PSECURITY_DESCRIPTOR* optional, out
    ctypes.POINTER(wintypes.DWORD),  # NewSecurityDescriptorLength : DWORD* optional, out
    ctypes.c_byte,  # CheckOnly : BOOLEAN
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('ntdll.dll')
RtlNormalizeSecurityDescriptor = Fiddle::Function.new(
  lib['RtlNormalizeSecurityDescriptor'],
  [
    Fiddle::TYPE_VOIDP,  # SecurityDescriptor : PSECURITY_DESCRIPTOR* in/out
    -Fiddle::TYPE_INT,  # SecurityDescriptorLength : DWORD
    Fiddle::TYPE_VOIDP,  # NewSecurityDescriptor : PSECURITY_DESCRIPTOR* optional, out
    Fiddle::TYPE_VOIDP,  # NewSecurityDescriptorLength : DWORD* optional, out
    Fiddle::TYPE_CHAR,  # CheckOnly : BOOLEAN
  ],
  Fiddle::TYPE_CHAR)
#[link(name = "ntdll")]
extern "system" {
    fn RtlNormalizeSecurityDescriptor(
        SecurityDescriptor: *mut *mut core::ffi::c_void,  // PSECURITY_DESCRIPTOR* in/out
        SecurityDescriptorLength: u32,  // DWORD
        NewSecurityDescriptor: *mut *mut core::ffi::c_void,  // PSECURITY_DESCRIPTOR* optional, out
        NewSecurityDescriptorLength: *mut u32,  // DWORD* optional, out
        CheckOnly: u8  // BOOLEAN
    ) -> u8;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("ntdll.dll")]
public static extern byte RtlNormalizeSecurityDescriptor(IntPtr SecurityDescriptor, uint SecurityDescriptorLength, IntPtr NewSecurityDescriptor, IntPtr NewSecurityDescriptorLength, [MarshalAs(UnmanagedType.U1)] bool CheckOnly);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ntdll_RtlNormalizeSecurityDescriptor' -Namespace Win32 -PassThru
# $api::RtlNormalizeSecurityDescriptor(SecurityDescriptor, SecurityDescriptorLength, NewSecurityDescriptor, NewSecurityDescriptorLength, CheckOnly)
#uselib "ntdll.dll"
#func global RtlNormalizeSecurityDescriptor "RtlNormalizeSecurityDescriptor" sptr, sptr, sptr, sptr, sptr
; RtlNormalizeSecurityDescriptor SecurityDescriptor, SecurityDescriptorLength, NewSecurityDescriptor, varptr(NewSecurityDescriptorLength), CheckOnly   ; 戻り値は stat
; SecurityDescriptor : PSECURITY_DESCRIPTOR* in/out -> "sptr"
; SecurityDescriptorLength : DWORD -> "sptr"
; NewSecurityDescriptor : PSECURITY_DESCRIPTOR* optional, out -> "sptr"
; NewSecurityDescriptorLength : DWORD* optional, out -> "sptr"
; CheckOnly : BOOLEAN -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "ntdll.dll"
#cfunc global RtlNormalizeSecurityDescriptor "RtlNormalizeSecurityDescriptor" sptr, int, sptr, var, int
; res = RtlNormalizeSecurityDescriptor(SecurityDescriptor, SecurityDescriptorLength, NewSecurityDescriptor, NewSecurityDescriptorLength, CheckOnly)
; SecurityDescriptor : PSECURITY_DESCRIPTOR* in/out -> "sptr"
; SecurityDescriptorLength : DWORD -> "int"
; NewSecurityDescriptor : PSECURITY_DESCRIPTOR* optional, out -> "sptr"
; NewSecurityDescriptorLength : DWORD* optional, out -> "var"
; CheckOnly : BOOLEAN -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; BOOLEAN RtlNormalizeSecurityDescriptor(PSECURITY_DESCRIPTOR* SecurityDescriptor, DWORD SecurityDescriptorLength, PSECURITY_DESCRIPTOR* NewSecurityDescriptor, DWORD* NewSecurityDescriptorLength, BOOLEAN CheckOnly)
#uselib "ntdll.dll"
#cfunc global RtlNormalizeSecurityDescriptor "RtlNormalizeSecurityDescriptor" intptr, int, intptr, var, int
; res = RtlNormalizeSecurityDescriptor(SecurityDescriptor, SecurityDescriptorLength, NewSecurityDescriptor, NewSecurityDescriptorLength, CheckOnly)
; SecurityDescriptor : PSECURITY_DESCRIPTOR* in/out -> "intptr"
; SecurityDescriptorLength : DWORD -> "int"
; NewSecurityDescriptor : PSECURITY_DESCRIPTOR* optional, out -> "intptr"
; NewSecurityDescriptorLength : DWORD* optional, out -> "var"
; CheckOnly : BOOLEAN -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	ntdll = windows.NewLazySystemDLL("ntdll.dll")
	procRtlNormalizeSecurityDescriptor = ntdll.NewProc("RtlNormalizeSecurityDescriptor")
)

// SecurityDescriptor (PSECURITY_DESCRIPTOR* in/out), SecurityDescriptorLength (DWORD), NewSecurityDescriptor (PSECURITY_DESCRIPTOR* optional, out), NewSecurityDescriptorLength (DWORD* optional, out), CheckOnly (BOOLEAN)
r1, _, err := procRtlNormalizeSecurityDescriptor.Call(
	uintptr(SecurityDescriptor),
	uintptr(SecurityDescriptorLength),
	uintptr(NewSecurityDescriptor),
	uintptr(NewSecurityDescriptorLength),
	uintptr(CheckOnly),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOLEAN
function RtlNormalizeSecurityDescriptor(
  SecurityDescriptor: Pointer;   // PSECURITY_DESCRIPTOR* in/out
  SecurityDescriptorLength: DWORD;   // DWORD
  NewSecurityDescriptor: Pointer;   // PSECURITY_DESCRIPTOR* optional, out
  NewSecurityDescriptorLength: Pointer;   // DWORD* optional, out
  CheckOnly: ByteBool   // BOOLEAN
): ByteBool; stdcall;
  external 'ntdll.dll' name 'RtlNormalizeSecurityDescriptor';
result := DllCall("ntdll\RtlNormalizeSecurityDescriptor"
    , "Ptr", SecurityDescriptor   ; PSECURITY_DESCRIPTOR* in/out
    , "UInt", SecurityDescriptorLength   ; DWORD
    , "Ptr", NewSecurityDescriptor   ; PSECURITY_DESCRIPTOR* optional, out
    , "Ptr", NewSecurityDescriptorLength   ; DWORD* optional, out
    , "Char", CheckOnly   ; BOOLEAN
    , "Char")   ; return: BOOLEAN
●RtlNormalizeSecurityDescriptor(SecurityDescriptor, SecurityDescriptorLength, NewSecurityDescriptor, NewSecurityDescriptorLength, CheckOnly) = DLL("ntdll.dll", "byte RtlNormalizeSecurityDescriptor(void*, dword, void*, void*, byte)")
# 呼び出し: RtlNormalizeSecurityDescriptor(SecurityDescriptor, SecurityDescriptorLength, NewSecurityDescriptor, NewSecurityDescriptorLength, CheckOnly)
# SecurityDescriptor : PSECURITY_DESCRIPTOR* in/out -> "void*"
# SecurityDescriptorLength : DWORD -> "dword"
# NewSecurityDescriptor : PSECURITY_DESCRIPTOR* optional, out -> "void*"
# NewSecurityDescriptorLength : DWORD* optional, out -> "void*"
# CheckOnly : BOOLEAN -> "byte"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。