Win32 API 日本語リファレンス
ホームSecurity.Authentication.Identity › LsaQueryTrustedDomainInfo

LsaQueryTrustedDomainInfo

関数
SIDで指定した信頼ドメインの情報を取得する。
DLLADVAPI32.dll呼出規約winapi対応OSWindows XP 以降

シグネチャ

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

NTSTATUS LsaQueryTrustedDomainInfo(
    LSA_HANDLE PolicyHandle,
    PSID TrustedDomainSid,
    TRUSTED_INFORMATION_CLASS InformationClass,
    void** Buffer
);

パラメーター

名前方向説明
PolicyHandleLSA_HANDLEinLsaOpenPolicyで取得したLSAポリシーハンドル。信頼ドメイン照会権が必要となる。
TrustedDomainSidPSIDin情報を取得する対象の信頼ドメインのSID。有効なPSIDを指定する。
InformationClassTRUSTED_INFORMATION_CLASSin取得する信頼ドメイン情報の種類を示すTRUSTED_INFORMATION_CLASS列挙値。
Buffervoid**out出力。要求した情報クラスに対応する構造体を受け取るバッファへのポインタ。LsaFreeMemoryで解放する。

戻り値の型: NTSTATUS

各言語での呼び出し定義

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

NTSTATUS LsaQueryTrustedDomainInfo(
    LSA_HANDLE PolicyHandle,
    PSID TrustedDomainSid,
    TRUSTED_INFORMATION_CLASS InformationClass,
    void** Buffer
);
[DllImport("ADVAPI32.dll", ExactSpelling = true)]
static extern int LsaQueryTrustedDomainInfo(
    IntPtr PolicyHandle,   // LSA_HANDLE
    IntPtr TrustedDomainSid,   // PSID
    int InformationClass,   // TRUSTED_INFORMATION_CLASS
    IntPtr Buffer   // void** out
);
<DllImport("ADVAPI32.dll", ExactSpelling:=True)>
Public Shared Function LsaQueryTrustedDomainInfo(
    PolicyHandle As IntPtr,   ' LSA_HANDLE
    TrustedDomainSid As IntPtr,   ' PSID
    InformationClass As Integer,   ' TRUSTED_INFORMATION_CLASS
    Buffer As IntPtr   ' void** out
) As Integer
End Function
' PolicyHandle : LSA_HANDLE
' TrustedDomainSid : PSID
' InformationClass : TRUSTED_INFORMATION_CLASS
' Buffer : void** out
Declare PtrSafe Function LsaQueryTrustedDomainInfo Lib "advapi32" ( _
    ByVal PolicyHandle As LongPtr, _
    ByVal TrustedDomainSid As LongPtr, _
    ByVal InformationClass As Long, _
    ByVal Buffer As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

LsaQueryTrustedDomainInfo = ctypes.windll.advapi32.LsaQueryTrustedDomainInfo
LsaQueryTrustedDomainInfo.restype = ctypes.c_int
LsaQueryTrustedDomainInfo.argtypes = [
    ctypes.c_ssize_t,  # PolicyHandle : LSA_HANDLE
    wintypes.HANDLE,  # TrustedDomainSid : PSID
    ctypes.c_int,  # InformationClass : TRUSTED_INFORMATION_CLASS
    ctypes.c_void_p,  # Buffer : void** out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('ADVAPI32.dll')
LsaQueryTrustedDomainInfo = Fiddle::Function.new(
  lib['LsaQueryTrustedDomainInfo'],
  [
    Fiddle::TYPE_INTPTR_T,  # PolicyHandle : LSA_HANDLE
    Fiddle::TYPE_VOIDP,  # TrustedDomainSid : PSID
    Fiddle::TYPE_INT,  # InformationClass : TRUSTED_INFORMATION_CLASS
    Fiddle::TYPE_VOIDP,  # Buffer : void** out
  ],
  Fiddle::TYPE_INT)
#[link(name = "advapi32")]
extern "system" {
    fn LsaQueryTrustedDomainInfo(
        PolicyHandle: isize,  // LSA_HANDLE
        TrustedDomainSid: *mut core::ffi::c_void,  // PSID
        InformationClass: i32,  // TRUSTED_INFORMATION_CLASS
        Buffer: *mut *mut ()  // void** out
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("ADVAPI32.dll")]
public static extern int LsaQueryTrustedDomainInfo(IntPtr PolicyHandle, IntPtr TrustedDomainSid, int InformationClass, IntPtr Buffer);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ADVAPI32_LsaQueryTrustedDomainInfo' -Namespace Win32 -PassThru
# $api::LsaQueryTrustedDomainInfo(PolicyHandle, TrustedDomainSid, InformationClass, Buffer)
#uselib "ADVAPI32.dll"
#func global LsaQueryTrustedDomainInfo "LsaQueryTrustedDomainInfo" sptr, sptr, sptr, sptr
; LsaQueryTrustedDomainInfo PolicyHandle, TrustedDomainSid, InformationClass, Buffer   ; 戻り値は stat
; PolicyHandle : LSA_HANDLE -> "sptr"
; TrustedDomainSid : PSID -> "sptr"
; InformationClass : TRUSTED_INFORMATION_CLASS -> "sptr"
; Buffer : void** out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "ADVAPI32.dll"
#cfunc global LsaQueryTrustedDomainInfo "LsaQueryTrustedDomainInfo" sptr, sptr, int, sptr
; res = LsaQueryTrustedDomainInfo(PolicyHandle, TrustedDomainSid, InformationClass, Buffer)
; PolicyHandle : LSA_HANDLE -> "sptr"
; TrustedDomainSid : PSID -> "sptr"
; InformationClass : TRUSTED_INFORMATION_CLASS -> "int"
; Buffer : void** out -> "sptr"
; NTSTATUS LsaQueryTrustedDomainInfo(LSA_HANDLE PolicyHandle, PSID TrustedDomainSid, TRUSTED_INFORMATION_CLASS InformationClass, void** Buffer)
#uselib "ADVAPI32.dll"
#cfunc global LsaQueryTrustedDomainInfo "LsaQueryTrustedDomainInfo" intptr, intptr, int, intptr
; res = LsaQueryTrustedDomainInfo(PolicyHandle, TrustedDomainSid, InformationClass, Buffer)
; PolicyHandle : LSA_HANDLE -> "intptr"
; TrustedDomainSid : PSID -> "intptr"
; InformationClass : TRUSTED_INFORMATION_CLASS -> "int"
; Buffer : void** out -> "intptr"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	advapi32 = windows.NewLazySystemDLL("ADVAPI32.dll")
	procLsaQueryTrustedDomainInfo = advapi32.NewProc("LsaQueryTrustedDomainInfo")
)

// PolicyHandle (LSA_HANDLE), TrustedDomainSid (PSID), InformationClass (TRUSTED_INFORMATION_CLASS), Buffer (void** out)
r1, _, err := procLsaQueryTrustedDomainInfo.Call(
	uintptr(PolicyHandle),
	uintptr(TrustedDomainSid),
	uintptr(InformationClass),
	uintptr(Buffer),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // NTSTATUS
function LsaQueryTrustedDomainInfo(
  PolicyHandle: NativeInt;   // LSA_HANDLE
  TrustedDomainSid: THandle;   // PSID
  InformationClass: Integer;   // TRUSTED_INFORMATION_CLASS
  Buffer: Pointer   // void** out
): Integer; stdcall;
  external 'ADVAPI32.dll' name 'LsaQueryTrustedDomainInfo';
result := DllCall("ADVAPI32\LsaQueryTrustedDomainInfo"
    , "Ptr", PolicyHandle   ; LSA_HANDLE
    , "Ptr", TrustedDomainSid   ; PSID
    , "Int", InformationClass   ; TRUSTED_INFORMATION_CLASS
    , "Ptr", Buffer   ; void** out
    , "Int")   ; return: NTSTATUS
●LsaQueryTrustedDomainInfo(PolicyHandle, TrustedDomainSid, InformationClass, Buffer) = DLL("ADVAPI32.dll", "int LsaQueryTrustedDomainInfo(int, void*, int, void*)")
# 呼び出し: LsaQueryTrustedDomainInfo(PolicyHandle, TrustedDomainSid, InformationClass, Buffer)
# PolicyHandle : LSA_HANDLE -> "int"
# TrustedDomainSid : PSID -> "void*"
# InformationClass : TRUSTED_INFORMATION_CLASS -> "int"
# Buffer : void** out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

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

typedef LsaQueryTrustedDomainInfoNative = Int32 Function(IntPtr, Pointer<Void>, Int32, Pointer<Void>);
typedef LsaQueryTrustedDomainInfoDart = int Function(int, Pointer<Void>, int, Pointer<Void>);
final LsaQueryTrustedDomainInfo = DynamicLibrary.open('ADVAPI32.dll')
    .lookupFunction<LsaQueryTrustedDomainInfoNative, LsaQueryTrustedDomainInfoDart>('LsaQueryTrustedDomainInfo');
// PolicyHandle : LSA_HANDLE -> IntPtr
// TrustedDomainSid : PSID -> Pointer<Void>
// InformationClass : TRUSTED_INFORMATION_CLASS -> Int32
// Buffer : void** out -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function LsaQueryTrustedDomainInfo(
  PolicyHandle: NativeInt;   // LSA_HANDLE
  TrustedDomainSid: THandle;   // PSID
  InformationClass: Integer;   // TRUSTED_INFORMATION_CLASS
  Buffer: Pointer   // void** out
): Integer; stdcall;
  external 'ADVAPI32.dll' name 'LsaQueryTrustedDomainInfo';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "LsaQueryTrustedDomainInfo"
  c_LsaQueryTrustedDomainInfo :: CIntPtr -> Ptr () -> Int32 -> Ptr () -> IO Int32
-- PolicyHandle : LSA_HANDLE -> CIntPtr
-- TrustedDomainSid : PSID -> Ptr ()
-- InformationClass : TRUSTED_INFORMATION_CLASS -> Int32
-- Buffer : void** out -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let lsaquerytrusteddomaininfo =
  foreign "LsaQueryTrustedDomainInfo"
    (intptr_t @-> (ptr void) @-> int32_t @-> (ptr void) @-> returning int32_t)
(* PolicyHandle : LSA_HANDLE -> intptr_t *)
(* TrustedDomainSid : PSID -> (ptr void) *)
(* InformationClass : TRUSTED_INFORMATION_CLASS -> int32_t *)
(* Buffer : void** out -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library advapi32 (t "ADVAPI32.dll"))
(cffi:use-foreign-library advapi32)

(cffi:defcfun ("LsaQueryTrustedDomainInfo" lsa-query-trusted-domain-info :convention :stdcall) :int32
  (policy-handle :int64)   ; LSA_HANDLE
  (trusted-domain-sid :pointer)   ; PSID
  (information-class :int32)   ; TRUSTED_INFORMATION_CLASS
  (buffer :pointer))   ; void** out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $LsaQueryTrustedDomainInfo = Win32::API::More->new('ADVAPI32',
    'int LsaQueryTrustedDomainInfo(LPARAM PolicyHandle, HANDLE TrustedDomainSid, int InformationClass, LPVOID Buffer)');
# my $ret = $LsaQueryTrustedDomainInfo->Call($PolicyHandle, $TrustedDomainSid, $InformationClass, $Buffer);
# PolicyHandle : LSA_HANDLE -> LPARAM
# TrustedDomainSid : PSID -> HANDLE
# InformationClass : TRUSTED_INFORMATION_CLASS -> int
# Buffer : void** out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

使用する型