Win32 API 日本語リファレンス
ホームNetworking.ActiveDirectory › DsInheritSecurityIdentityW

DsInheritSecurityIdentityW

関数
移行元のSIDを移行先プリンシパルに継承させ移行元を削除する。
DLLNTDSAPI.dll文字セットUnicode (-W)呼出規約winapi対応OSWindows Vista 以降

シグネチャ

// NTDSAPI.dll  (Unicode / -W)
#include <windows.h>

DWORD DsInheritSecurityIdentityW(
    HANDLE hDS,
    DWORD Flags,   // optional
    LPCWSTR SrcPrincipal,
    LPCWSTR DstPrincipal
);

パラメーター

名前方向
hDSHANDLEin
FlagsDWORDoptional
SrcPrincipalLPCWSTRin
DstPrincipalLPCWSTRin

戻り値の型: DWORD

各言語での呼び出し定義

// NTDSAPI.dll  (Unicode / -W)
#include <windows.h>

DWORD DsInheritSecurityIdentityW(
    HANDLE hDS,
    DWORD Flags,   // optional
    LPCWSTR SrcPrincipal,
    LPCWSTR DstPrincipal
);
[DllImport("NTDSAPI.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern uint DsInheritSecurityIdentityW(
    IntPtr hDS,   // HANDLE
    uint Flags,   // DWORD optional
    [MarshalAs(UnmanagedType.LPWStr)] string SrcPrincipal,   // LPCWSTR
    [MarshalAs(UnmanagedType.LPWStr)] string DstPrincipal   // LPCWSTR
);
<DllImport("NTDSAPI.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function DsInheritSecurityIdentityW(
    hDS As IntPtr,   ' HANDLE
    Flags As UInteger,   ' DWORD optional
    <MarshalAs(UnmanagedType.LPWStr)> SrcPrincipal As String,   ' LPCWSTR
    <MarshalAs(UnmanagedType.LPWStr)> DstPrincipal As String   ' LPCWSTR
) As UInteger
End Function
' hDS : HANDLE
' Flags : DWORD optional
' SrcPrincipal : LPCWSTR
' DstPrincipal : LPCWSTR
Declare PtrSafe Function DsInheritSecurityIdentityW Lib "ntdsapi" ( _
    ByVal hDS As LongPtr, _
    ByVal Flags As Long, _
    ByVal SrcPrincipal As LongPtr, _
    ByVal DstPrincipal As LongPtr) As Long
' Unicode(W): 文字列は ByVal As LongPtr とし StrPtr(unicodeStr) を渡す
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

DsInheritSecurityIdentityW = ctypes.windll.ntdsapi.DsInheritSecurityIdentityW
DsInheritSecurityIdentityW.restype = wintypes.DWORD
DsInheritSecurityIdentityW.argtypes = [
    wintypes.HANDLE,  # hDS : HANDLE
    wintypes.DWORD,  # Flags : DWORD optional
    wintypes.LPCWSTR,  # SrcPrincipal : LPCWSTR
    wintypes.LPCWSTR,  # DstPrincipal : LPCWSTR
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('NTDSAPI.dll')
DsInheritSecurityIdentityW = Fiddle::Function.new(
  lib['DsInheritSecurityIdentityW'],
  [
    Fiddle::TYPE_VOIDP,  # hDS : HANDLE
    -Fiddle::TYPE_INT,  # Flags : DWORD optional
    Fiddle::TYPE_VOIDP,  # SrcPrincipal : LPCWSTR
    Fiddle::TYPE_VOIDP,  # DstPrincipal : LPCWSTR
  ],
  -Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "ntdsapi")]
extern "system" {
    fn DsInheritSecurityIdentityW(
        hDS: *mut core::ffi::c_void,  // HANDLE
        Flags: u32,  // DWORD optional
        SrcPrincipal: *const u16,  // LPCWSTR
        DstPrincipal: *const u16  // LPCWSTR
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("NTDSAPI.dll", CharSet = CharSet.Unicode)]
public static extern uint DsInheritSecurityIdentityW(IntPtr hDS, uint Flags, [MarshalAs(UnmanagedType.LPWStr)] string SrcPrincipal, [MarshalAs(UnmanagedType.LPWStr)] string DstPrincipal);
"@
$api = Add-Type -MemberDefinition $sig -Name 'NTDSAPI_DsInheritSecurityIdentityW' -Namespace Win32 -PassThru
# $api::DsInheritSecurityIdentityW(hDS, Flags, SrcPrincipal, DstPrincipal)
#uselib "NTDSAPI.dll"
#func global DsInheritSecurityIdentityW "DsInheritSecurityIdentityW" wptr, wptr, wptr, wptr
; DsInheritSecurityIdentityW hDS, Flags, SrcPrincipal, DstPrincipal   ; 戻り値は stat
; hDS : HANDLE -> "wptr"
; Flags : DWORD optional -> "wptr"
; SrcPrincipal : LPCWSTR -> "wptr"
; DstPrincipal : LPCWSTR -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "NTDSAPI.dll"
#cfunc global DsInheritSecurityIdentityW "DsInheritSecurityIdentityW" sptr, int, wstr, wstr
; res = DsInheritSecurityIdentityW(hDS, Flags, SrcPrincipal, DstPrincipal)
; hDS : HANDLE -> "sptr"
; Flags : DWORD optional -> "int"
; SrcPrincipal : LPCWSTR -> "wstr"
; DstPrincipal : LPCWSTR -> "wstr"
; DWORD DsInheritSecurityIdentityW(HANDLE hDS, DWORD Flags, LPCWSTR SrcPrincipal, LPCWSTR DstPrincipal)
#uselib "NTDSAPI.dll"
#cfunc global DsInheritSecurityIdentityW "DsInheritSecurityIdentityW" intptr, int, wstr, wstr
; res = DsInheritSecurityIdentityW(hDS, Flags, SrcPrincipal, DstPrincipal)
; hDS : HANDLE -> "intptr"
; Flags : DWORD optional -> "int"
; SrcPrincipal : LPCWSTR -> "wstr"
; DstPrincipal : LPCWSTR -> "wstr"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	ntdsapi = windows.NewLazySystemDLL("NTDSAPI.dll")
	procDsInheritSecurityIdentityW = ntdsapi.NewProc("DsInheritSecurityIdentityW")
)

// hDS (HANDLE), Flags (DWORD optional), SrcPrincipal (LPCWSTR), DstPrincipal (LPCWSTR)
r1, _, err := procDsInheritSecurityIdentityW.Call(
	uintptr(hDS),
	uintptr(Flags),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(SrcPrincipal))),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(DstPrincipal))),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // DWORD
function DsInheritSecurityIdentityW(
  hDS: THandle;   // HANDLE
  Flags: DWORD;   // DWORD optional
  SrcPrincipal: PWideChar;   // LPCWSTR
  DstPrincipal: PWideChar   // LPCWSTR
): DWORD; stdcall;
  external 'NTDSAPI.dll' name 'DsInheritSecurityIdentityW';
result := DllCall("NTDSAPI\DsInheritSecurityIdentityW"
    , "Ptr", hDS   ; HANDLE
    , "UInt", Flags   ; DWORD optional
    , "WStr", SrcPrincipal   ; LPCWSTR
    , "WStr", DstPrincipal   ; LPCWSTR
    , "UInt")   ; return: DWORD
●DsInheritSecurityIdentityW(hDS, Flags, SrcPrincipal, DstPrincipal) = DLL("NTDSAPI.dll", "dword DsInheritSecurityIdentityW(void*, dword, char*, char*)")
# 呼び出し: DsInheritSecurityIdentityW(hDS, Flags, SrcPrincipal, DstPrincipal)
# hDS : HANDLE -> "void*"
# Flags : DWORD optional -> "dword"
# SrcPrincipal : LPCWSTR -> "char*"
# DstPrincipal : LPCWSTR -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。