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

BinarySDToSecurityDescriptor

関数
バイナリ形式のセキュリティ記述子をVARIANTオブジェクトへ変換する。
DLLACTIVEDS.dll呼出規約winapi対応OSWindows Vista 以降

シグネチャ

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

HRESULT BinarySDToSecurityDescriptor(
    PSECURITY_DESCRIPTOR pSecurityDescriptor,
    VARIANT* pVarsec,
    LPCWSTR pszServerName,
    LPCWSTR userName,
    LPCWSTR passWord,
    DWORD dwFlags
);

パラメーター

名前方向
pSecurityDescriptorPSECURITY_DESCRIPTORin
pVarsecVARIANT*inout
pszServerNameLPCWSTRin
userNameLPCWSTRin
passWordLPCWSTRin
dwFlagsDWORDin

戻り値の型: HRESULT

各言語での呼び出し定義

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

HRESULT BinarySDToSecurityDescriptor(
    PSECURITY_DESCRIPTOR pSecurityDescriptor,
    VARIANT* pVarsec,
    LPCWSTR pszServerName,
    LPCWSTR userName,
    LPCWSTR passWord,
    DWORD dwFlags
);
[DllImport("ACTIVEDS.dll", ExactSpelling = true)]
static extern int BinarySDToSecurityDescriptor(
    IntPtr pSecurityDescriptor,   // PSECURITY_DESCRIPTOR
    IntPtr pVarsec,   // VARIANT* in/out
    [MarshalAs(UnmanagedType.LPWStr)] string pszServerName,   // LPCWSTR
    [MarshalAs(UnmanagedType.LPWStr)] string userName,   // LPCWSTR
    [MarshalAs(UnmanagedType.LPWStr)] string passWord,   // LPCWSTR
    uint dwFlags   // DWORD
);
<DllImport("ACTIVEDS.dll", ExactSpelling:=True)>
Public Shared Function BinarySDToSecurityDescriptor(
    pSecurityDescriptor As IntPtr,   ' PSECURITY_DESCRIPTOR
    pVarsec As IntPtr,   ' VARIANT* in/out
    <MarshalAs(UnmanagedType.LPWStr)> pszServerName As String,   ' LPCWSTR
    <MarshalAs(UnmanagedType.LPWStr)> userName As String,   ' LPCWSTR
    <MarshalAs(UnmanagedType.LPWStr)> passWord As String,   ' LPCWSTR
    dwFlags As UInteger   ' DWORD
) As Integer
End Function
' pSecurityDescriptor : PSECURITY_DESCRIPTOR
' pVarsec : VARIANT* in/out
' pszServerName : LPCWSTR
' userName : LPCWSTR
' passWord : LPCWSTR
' dwFlags : DWORD
Declare PtrSafe Function BinarySDToSecurityDescriptor Lib "activeds" ( _
    ByVal pSecurityDescriptor As LongPtr, _
    ByVal pVarsec As LongPtr, _
    ByVal pszServerName As LongPtr, _
    ByVal userName As LongPtr, _
    ByVal passWord As LongPtr, _
    ByVal dwFlags As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

BinarySDToSecurityDescriptor = ctypes.windll.activeds.BinarySDToSecurityDescriptor
BinarySDToSecurityDescriptor.restype = ctypes.c_int
BinarySDToSecurityDescriptor.argtypes = [
    wintypes.HANDLE,  # pSecurityDescriptor : PSECURITY_DESCRIPTOR
    ctypes.c_void_p,  # pVarsec : VARIANT* in/out
    wintypes.LPCWSTR,  # pszServerName : LPCWSTR
    wintypes.LPCWSTR,  # userName : LPCWSTR
    wintypes.LPCWSTR,  # passWord : LPCWSTR
    wintypes.DWORD,  # dwFlags : DWORD
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('ACTIVEDS.dll')
BinarySDToSecurityDescriptor = Fiddle::Function.new(
  lib['BinarySDToSecurityDescriptor'],
  [
    Fiddle::TYPE_VOIDP,  # pSecurityDescriptor : PSECURITY_DESCRIPTOR
    Fiddle::TYPE_VOIDP,  # pVarsec : VARIANT* in/out
    Fiddle::TYPE_VOIDP,  # pszServerName : LPCWSTR
    Fiddle::TYPE_VOIDP,  # userName : LPCWSTR
    Fiddle::TYPE_VOIDP,  # passWord : LPCWSTR
    -Fiddle::TYPE_INT,  # dwFlags : DWORD
  ],
  Fiddle::TYPE_INT)
#[link(name = "activeds")]
extern "system" {
    fn BinarySDToSecurityDescriptor(
        pSecurityDescriptor: *mut core::ffi::c_void,  // PSECURITY_DESCRIPTOR
        pVarsec: *mut VARIANT,  // VARIANT* in/out
        pszServerName: *const u16,  // LPCWSTR
        userName: *const u16,  // LPCWSTR
        passWord: *const u16,  // LPCWSTR
        dwFlags: u32  // DWORD
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("ACTIVEDS.dll")]
public static extern int BinarySDToSecurityDescriptor(IntPtr pSecurityDescriptor, IntPtr pVarsec, [MarshalAs(UnmanagedType.LPWStr)] string pszServerName, [MarshalAs(UnmanagedType.LPWStr)] string userName, [MarshalAs(UnmanagedType.LPWStr)] string passWord, uint dwFlags);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ACTIVEDS_BinarySDToSecurityDescriptor' -Namespace Win32 -PassThru
# $api::BinarySDToSecurityDescriptor(pSecurityDescriptor, pVarsec, pszServerName, userName, passWord, dwFlags)
#uselib "ACTIVEDS.dll"
#func global BinarySDToSecurityDescriptor "BinarySDToSecurityDescriptor" sptr, sptr, sptr, sptr, sptr, sptr
; BinarySDToSecurityDescriptor pSecurityDescriptor, varptr(pVarsec), pszServerName, userName, passWord, dwFlags   ; 戻り値は stat
; pSecurityDescriptor : PSECURITY_DESCRIPTOR -> "sptr"
; pVarsec : VARIANT* in/out -> "sptr"
; pszServerName : LPCWSTR -> "sptr"
; userName : LPCWSTR -> "sptr"
; passWord : LPCWSTR -> "sptr"
; dwFlags : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "ACTIVEDS.dll"
#cfunc global BinarySDToSecurityDescriptor "BinarySDToSecurityDescriptor" sptr, var, wstr, wstr, wstr, int
; res = BinarySDToSecurityDescriptor(pSecurityDescriptor, pVarsec, pszServerName, userName, passWord, dwFlags)
; pSecurityDescriptor : PSECURITY_DESCRIPTOR -> "sptr"
; pVarsec : VARIANT* in/out -> "var"
; pszServerName : LPCWSTR -> "wstr"
; userName : LPCWSTR -> "wstr"
; passWord : LPCWSTR -> "wstr"
; dwFlags : DWORD -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; HRESULT BinarySDToSecurityDescriptor(PSECURITY_DESCRIPTOR pSecurityDescriptor, VARIANT* pVarsec, LPCWSTR pszServerName, LPCWSTR userName, LPCWSTR passWord, DWORD dwFlags)
#uselib "ACTIVEDS.dll"
#cfunc global BinarySDToSecurityDescriptor "BinarySDToSecurityDescriptor" intptr, var, wstr, wstr, wstr, int
; res = BinarySDToSecurityDescriptor(pSecurityDescriptor, pVarsec, pszServerName, userName, passWord, dwFlags)
; pSecurityDescriptor : PSECURITY_DESCRIPTOR -> "intptr"
; pVarsec : VARIANT* in/out -> "var"
; pszServerName : LPCWSTR -> "wstr"
; userName : LPCWSTR -> "wstr"
; passWord : LPCWSTR -> "wstr"
; dwFlags : DWORD -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	activeds = windows.NewLazySystemDLL("ACTIVEDS.dll")
	procBinarySDToSecurityDescriptor = activeds.NewProc("BinarySDToSecurityDescriptor")
)

// pSecurityDescriptor (PSECURITY_DESCRIPTOR), pVarsec (VARIANT* in/out), pszServerName (LPCWSTR), userName (LPCWSTR), passWord (LPCWSTR), dwFlags (DWORD)
r1, _, err := procBinarySDToSecurityDescriptor.Call(
	uintptr(pSecurityDescriptor),
	uintptr(pVarsec),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pszServerName))),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(userName))),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(passWord))),
	uintptr(dwFlags),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HRESULT
function BinarySDToSecurityDescriptor(
  pSecurityDescriptor: THandle;   // PSECURITY_DESCRIPTOR
  pVarsec: Pointer;   // VARIANT* in/out
  pszServerName: PWideChar;   // LPCWSTR
  userName: PWideChar;   // LPCWSTR
  passWord: PWideChar;   // LPCWSTR
  dwFlags: DWORD   // DWORD
): Integer; stdcall;
  external 'ACTIVEDS.dll' name 'BinarySDToSecurityDescriptor';
result := DllCall("ACTIVEDS\BinarySDToSecurityDescriptor"
    , "Ptr", pSecurityDescriptor   ; PSECURITY_DESCRIPTOR
    , "Ptr", pVarsec   ; VARIANT* in/out
    , "WStr", pszServerName   ; LPCWSTR
    , "WStr", userName   ; LPCWSTR
    , "WStr", passWord   ; LPCWSTR
    , "UInt", dwFlags   ; DWORD
    , "Int")   ; return: HRESULT
●BinarySDToSecurityDescriptor(pSecurityDescriptor, pVarsec, pszServerName, userName, passWord, dwFlags) = DLL("ACTIVEDS.dll", "int BinarySDToSecurityDescriptor(void*, void*, char*, char*, char*, dword)")
# 呼び出し: BinarySDToSecurityDescriptor(pSecurityDescriptor, pVarsec, pszServerName, userName, passWord, dwFlags)
# pSecurityDescriptor : PSECURITY_DESCRIPTOR -> "void*"
# pVarsec : VARIANT* in/out -> "void*"
# pszServerName : LPCWSTR -> "char*"
# userName : LPCWSTR -> "char*"
# passWord : LPCWSTR -> "char*"
# dwFlags : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。