LsaCallAuthenticationPackage
関数シグネチャ
// SECUR32.dll
#include <windows.h>
NTSTATUS LsaCallAuthenticationPackage(
HANDLE LsaHandle,
DWORD AuthenticationPackage,
void* ProtocolSubmitBuffer,
DWORD SubmitBufferLength,
void** ProtocolReturnBuffer, // optional
DWORD* ReturnBufferLength, // optional
INT* ProtocolStatus // optional
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| LsaHandle | HANDLE | in | 以前に LsaRegisterLogonProcess または LsaConnectUntrusted を呼び出して取得したハンドル。 |
| AuthenticationPackage | DWORD | in | 認証パッケージの識別子を指定します。この値は LsaLookupAuthenticationPackage を呼び出して取得します。 |
| ProtocolSubmitBuffer | void* | in | 認証パッケージに渡される、認証パッケージ固有のメッセージ バッファー。 このバッファーの形式と内容については、各認証パッケージのドキュメントを参照してください。 |
| SubmitBufferLength | DWORD | in | ProtocolSubmitBuffer バッファーの長さ (バイト単位) を示します。 |
| ProtocolReturnBuffer | void** | outoptional | 認証パッケージから返されるバッファーのアドレスを受け取るポインター。 このバッファーの形式と内容については、各認証パッケージのドキュメントを参照してください。 このバッファーはこの関数によって割り当てられます。このバッファーの使用が終わったら、LsaFreeReturnBuffer 関数を呼び出してメモリを解放してください。 |
| ReturnBufferLength | DWORD* | outoptional | 返されたバッファーの長さ (バイト単位) を受け取る ULONG へのポインター。 |
| ProtocolStatus | INT* | outoptional | 関数が成功した場合、このパラメーターは認証パッケージの完了状態を示す NTSTATUS コードを受け取ります。 |
戻り値の型: NTSTATUS
公式ドキュメント
ログオン アプリケーションが認証パッケージと通信するために使用します。
戻り値
関数が成功した場合、戻り値は STATUS_SUCCESS です。認証パッケージから返された状態を取得するには、ProtocolStatus パラメーターを確認してください。
関数が失敗した場合、戻り値は NTSTATUS コードです。考えられるエラー コードを次に示します。
| リターン コード | 説明 |
|---|---|
| クライアントのメモリ クォータが戻りバッファーを割り当てるのに不足しているため、呼び出しを完了できませんでした。 | |
| 指定された認証パッケージは LSA に認識されていません。 | |
| Kerberos クライアントが有効でない KDC 証明書を受信しました。デバイス ログオンでは厳密な KDC 検証が必要なため、KDC は "Kerberos Authentication" テンプレートまたは同等のテンプレートを使用する証明書を持っている必要があります。また、KDC 証明書の有効期限が切れているか失効している場合や、クライアントが誤ったサーバーに要求を送信させられる能動的な攻撃を受けている可能性もあります。 | |
| Kerberos クライアントが有効でないシステム証明書を使用しています。デバイス ログオンでは DNS 名が必要です。また、システム証明書の有効期限が切れているか、誤った証明書が選択されている可能性もあります。 |
詳細については、 LSA ポリシー関数の戻り値 を参照してください。
LsaNtStatusToWinError 関数は、NTSTATUS コードを Windows エラー コードに変換します。
解説(Remarks)
ログオン アプリケーションは、認証パッケージと通信するために LsaCallAuthenticationPackage を呼び出すことができます。アプリケーションがこれを行う理由はいくつかあります。
- NTLM チャレンジ/レスポンス プロトコルなど、複数のメッセージをやり取りする認証プロトコルを実装するため。
- 状態変更の情報を認証パッケージに渡すため。たとえば、以前は到達できなかったドメイン コントローラーに到達できるようになったことを、NTLM が MSV1_0 パッケージに通知する場合があります。認証パッケージはその後、そのドメイン コントローラーにログオンしていたすべてのユーザーを再ログオンさせます。
LOCAL_SYSTEM および NETWORK_SERVICE の PKINIT デバイス資格情報をクリーンアップするには、LsaCallAuthenticationPackage を呼び出す必要があります。PKINIT デバイス資格情報が存在しない場合、呼び出しが成功しても何も行われません。PKINIT デバイス資格情報が存在する場合、呼び出しが成功すると PKINIT デバイス資格情報がクリーンアップされ、パスワード資格情報のみが残ります。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// SECUR32.dll
#include <windows.h>
NTSTATUS LsaCallAuthenticationPackage(
HANDLE LsaHandle,
DWORD AuthenticationPackage,
void* ProtocolSubmitBuffer,
DWORD SubmitBufferLength,
void** ProtocolReturnBuffer, // optional
DWORD* ReturnBufferLength, // optional
INT* ProtocolStatus // optional
);[DllImport("SECUR32.dll", ExactSpelling = true)]
static extern int LsaCallAuthenticationPackage(
IntPtr LsaHandle, // HANDLE
uint AuthenticationPackage, // DWORD
IntPtr ProtocolSubmitBuffer, // void*
uint SubmitBufferLength, // DWORD
IntPtr ProtocolReturnBuffer, // void** optional, out
IntPtr ReturnBufferLength, // DWORD* optional, out
IntPtr ProtocolStatus // INT* optional, out
);<DllImport("SECUR32.dll", ExactSpelling:=True)>
Public Shared Function LsaCallAuthenticationPackage(
LsaHandle As IntPtr, ' HANDLE
AuthenticationPackage As UInteger, ' DWORD
ProtocolSubmitBuffer As IntPtr, ' void*
SubmitBufferLength As UInteger, ' DWORD
ProtocolReturnBuffer As IntPtr, ' void** optional, out
ReturnBufferLength As IntPtr, ' DWORD* optional, out
ProtocolStatus As IntPtr ' INT* optional, out
) As Integer
End Function' LsaHandle : HANDLE
' AuthenticationPackage : DWORD
' ProtocolSubmitBuffer : void*
' SubmitBufferLength : DWORD
' ProtocolReturnBuffer : void** optional, out
' ReturnBufferLength : DWORD* optional, out
' ProtocolStatus : INT* optional, out
Declare PtrSafe Function LsaCallAuthenticationPackage Lib "secur32" ( _
ByVal LsaHandle As LongPtr, _
ByVal AuthenticationPackage As Long, _
ByVal ProtocolSubmitBuffer As LongPtr, _
ByVal SubmitBufferLength As Long, _
ByVal ProtocolReturnBuffer As LongPtr, _
ByVal ReturnBufferLength As LongPtr, _
ByVal ProtocolStatus As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
LsaCallAuthenticationPackage = ctypes.windll.secur32.LsaCallAuthenticationPackage
LsaCallAuthenticationPackage.restype = ctypes.c_int
LsaCallAuthenticationPackage.argtypes = [
wintypes.HANDLE, # LsaHandle : HANDLE
wintypes.DWORD, # AuthenticationPackage : DWORD
ctypes.POINTER(None), # ProtocolSubmitBuffer : void*
wintypes.DWORD, # SubmitBufferLength : DWORD
ctypes.c_void_p, # ProtocolReturnBuffer : void** optional, out
ctypes.POINTER(wintypes.DWORD), # ReturnBufferLength : DWORD* optional, out
ctypes.POINTER(ctypes.c_int), # ProtocolStatus : INT* optional, out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('SECUR32.dll')
LsaCallAuthenticationPackage = Fiddle::Function.new(
lib['LsaCallAuthenticationPackage'],
[
Fiddle::TYPE_VOIDP, # LsaHandle : HANDLE
-Fiddle::TYPE_INT, # AuthenticationPackage : DWORD
Fiddle::TYPE_VOIDP, # ProtocolSubmitBuffer : void*
-Fiddle::TYPE_INT, # SubmitBufferLength : DWORD
Fiddle::TYPE_VOIDP, # ProtocolReturnBuffer : void** optional, out
Fiddle::TYPE_VOIDP, # ReturnBufferLength : DWORD* optional, out
Fiddle::TYPE_VOIDP, # ProtocolStatus : INT* optional, out
],
Fiddle::TYPE_INT)#[link(name = "secur32")]
extern "system" {
fn LsaCallAuthenticationPackage(
LsaHandle: *mut core::ffi::c_void, // HANDLE
AuthenticationPackage: u32, // DWORD
ProtocolSubmitBuffer: *mut (), // void*
SubmitBufferLength: u32, // DWORD
ProtocolReturnBuffer: *mut *mut (), // void** optional, out
ReturnBufferLength: *mut u32, // DWORD* optional, out
ProtocolStatus: *mut i32 // INT* optional, out
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("SECUR32.dll")]
public static extern int LsaCallAuthenticationPackage(IntPtr LsaHandle, uint AuthenticationPackage, IntPtr ProtocolSubmitBuffer, uint SubmitBufferLength, IntPtr ProtocolReturnBuffer, IntPtr ReturnBufferLength, IntPtr ProtocolStatus);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SECUR32_LsaCallAuthenticationPackage' -Namespace Win32 -PassThru
# $api::LsaCallAuthenticationPackage(LsaHandle, AuthenticationPackage, ProtocolSubmitBuffer, SubmitBufferLength, ProtocolReturnBuffer, ReturnBufferLength, ProtocolStatus)#uselib "SECUR32.dll"
#func global LsaCallAuthenticationPackage "LsaCallAuthenticationPackage" sptr, sptr, sptr, sptr, sptr, sptr, sptr
; LsaCallAuthenticationPackage LsaHandle, AuthenticationPackage, ProtocolSubmitBuffer, SubmitBufferLength, ProtocolReturnBuffer, varptr(ReturnBufferLength), varptr(ProtocolStatus) ; 戻り値は stat
; LsaHandle : HANDLE -> "sptr"
; AuthenticationPackage : DWORD -> "sptr"
; ProtocolSubmitBuffer : void* -> "sptr"
; SubmitBufferLength : DWORD -> "sptr"
; ProtocolReturnBuffer : void** optional, out -> "sptr"
; ReturnBufferLength : DWORD* optional, out -> "sptr"
; ProtocolStatus : INT* optional, out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "SECUR32.dll" #cfunc global LsaCallAuthenticationPackage "LsaCallAuthenticationPackage" sptr, int, sptr, int, sptr, var, var ; res = LsaCallAuthenticationPackage(LsaHandle, AuthenticationPackage, ProtocolSubmitBuffer, SubmitBufferLength, ProtocolReturnBuffer, ReturnBufferLength, ProtocolStatus) ; LsaHandle : HANDLE -> "sptr" ; AuthenticationPackage : DWORD -> "int" ; ProtocolSubmitBuffer : void* -> "sptr" ; SubmitBufferLength : DWORD -> "int" ; ProtocolReturnBuffer : void** optional, out -> "sptr" ; ReturnBufferLength : DWORD* optional, out -> "var" ; ProtocolStatus : INT* optional, out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "SECUR32.dll" #cfunc global LsaCallAuthenticationPackage "LsaCallAuthenticationPackage" sptr, int, sptr, int, sptr, sptr, sptr ; res = LsaCallAuthenticationPackage(LsaHandle, AuthenticationPackage, ProtocolSubmitBuffer, SubmitBufferLength, ProtocolReturnBuffer, varptr(ReturnBufferLength), varptr(ProtocolStatus)) ; LsaHandle : HANDLE -> "sptr" ; AuthenticationPackage : DWORD -> "int" ; ProtocolSubmitBuffer : void* -> "sptr" ; SubmitBufferLength : DWORD -> "int" ; ProtocolReturnBuffer : void** optional, out -> "sptr" ; ReturnBufferLength : DWORD* optional, out -> "sptr" ; ProtocolStatus : INT* optional, out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
; NTSTATUS LsaCallAuthenticationPackage(HANDLE LsaHandle, DWORD AuthenticationPackage, void* ProtocolSubmitBuffer, DWORD SubmitBufferLength, void** ProtocolReturnBuffer, DWORD* ReturnBufferLength, INT* ProtocolStatus) #uselib "SECUR32.dll" #cfunc global LsaCallAuthenticationPackage "LsaCallAuthenticationPackage" intptr, int, intptr, int, intptr, var, var ; res = LsaCallAuthenticationPackage(LsaHandle, AuthenticationPackage, ProtocolSubmitBuffer, SubmitBufferLength, ProtocolReturnBuffer, ReturnBufferLength, ProtocolStatus) ; LsaHandle : HANDLE -> "intptr" ; AuthenticationPackage : DWORD -> "int" ; ProtocolSubmitBuffer : void* -> "intptr" ; SubmitBufferLength : DWORD -> "int" ; ProtocolReturnBuffer : void** optional, out -> "intptr" ; ReturnBufferLength : DWORD* optional, out -> "var" ; ProtocolStatus : INT* optional, out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; NTSTATUS LsaCallAuthenticationPackage(HANDLE LsaHandle, DWORD AuthenticationPackage, void* ProtocolSubmitBuffer, DWORD SubmitBufferLength, void** ProtocolReturnBuffer, DWORD* ReturnBufferLength, INT* ProtocolStatus) #uselib "SECUR32.dll" #cfunc global LsaCallAuthenticationPackage "LsaCallAuthenticationPackage" intptr, int, intptr, int, intptr, intptr, intptr ; res = LsaCallAuthenticationPackage(LsaHandle, AuthenticationPackage, ProtocolSubmitBuffer, SubmitBufferLength, ProtocolReturnBuffer, varptr(ReturnBufferLength), varptr(ProtocolStatus)) ; LsaHandle : HANDLE -> "intptr" ; AuthenticationPackage : DWORD -> "int" ; ProtocolSubmitBuffer : void* -> "intptr" ; SubmitBufferLength : DWORD -> "int" ; ProtocolReturnBuffer : void** optional, out -> "intptr" ; ReturnBufferLength : DWORD* optional, out -> "intptr" ; ProtocolStatus : INT* optional, out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
secur32 = windows.NewLazySystemDLL("SECUR32.dll")
procLsaCallAuthenticationPackage = secur32.NewProc("LsaCallAuthenticationPackage")
)
// LsaHandle (HANDLE), AuthenticationPackage (DWORD), ProtocolSubmitBuffer (void*), SubmitBufferLength (DWORD), ProtocolReturnBuffer (void** optional, out), ReturnBufferLength (DWORD* optional, out), ProtocolStatus (INT* optional, out)
r1, _, err := procLsaCallAuthenticationPackage.Call(
uintptr(LsaHandle),
uintptr(AuthenticationPackage),
uintptr(ProtocolSubmitBuffer),
uintptr(SubmitBufferLength),
uintptr(ProtocolReturnBuffer),
uintptr(ReturnBufferLength),
uintptr(ProtocolStatus),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // NTSTATUSfunction LsaCallAuthenticationPackage(
LsaHandle: THandle; // HANDLE
AuthenticationPackage: DWORD; // DWORD
ProtocolSubmitBuffer: Pointer; // void*
SubmitBufferLength: DWORD; // DWORD
ProtocolReturnBuffer: Pointer; // void** optional, out
ReturnBufferLength: Pointer; // DWORD* optional, out
ProtocolStatus: Pointer // INT* optional, out
): Integer; stdcall;
external 'SECUR32.dll' name 'LsaCallAuthenticationPackage';result := DllCall("SECUR32\LsaCallAuthenticationPackage"
, "Ptr", LsaHandle ; HANDLE
, "UInt", AuthenticationPackage ; DWORD
, "Ptr", ProtocolSubmitBuffer ; void*
, "UInt", SubmitBufferLength ; DWORD
, "Ptr", ProtocolReturnBuffer ; void** optional, out
, "Ptr", ReturnBufferLength ; DWORD* optional, out
, "Ptr", ProtocolStatus ; INT* optional, out
, "Int") ; return: NTSTATUS●LsaCallAuthenticationPackage(LsaHandle, AuthenticationPackage, ProtocolSubmitBuffer, SubmitBufferLength, ProtocolReturnBuffer, ReturnBufferLength, ProtocolStatus) = DLL("SECUR32.dll", "int LsaCallAuthenticationPackage(void*, dword, void*, dword, void*, void*, void*)")
# 呼び出し: LsaCallAuthenticationPackage(LsaHandle, AuthenticationPackage, ProtocolSubmitBuffer, SubmitBufferLength, ProtocolReturnBuffer, ReturnBufferLength, ProtocolStatus)
# LsaHandle : HANDLE -> "void*"
# AuthenticationPackage : DWORD -> "dword"
# ProtocolSubmitBuffer : void* -> "void*"
# SubmitBufferLength : DWORD -> "dword"
# ProtocolReturnBuffer : void** optional, out -> "void*"
# ReturnBufferLength : DWORD* optional, out -> "void*"
# ProtocolStatus : INT* optional, out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "secur32" fn LsaCallAuthenticationPackage(
LsaHandle: ?*anyopaque, // HANDLE
AuthenticationPackage: u32, // DWORD
ProtocolSubmitBuffer: ?*anyopaque, // void*
SubmitBufferLength: u32, // DWORD
ProtocolReturnBuffer: ?*anyopaque, // void** optional, out
ReturnBufferLength: [*c]u32, // DWORD* optional, out
ProtocolStatus: [*c]i32 // INT* optional, out
) callconv(std.os.windows.WINAPI) i32;proc LsaCallAuthenticationPackage(
LsaHandle: pointer, # HANDLE
AuthenticationPackage: uint32, # DWORD
ProtocolSubmitBuffer: pointer, # void*
SubmitBufferLength: uint32, # DWORD
ProtocolReturnBuffer: pointer, # void** optional, out
ReturnBufferLength: ptr uint32, # DWORD* optional, out
ProtocolStatus: ptr int32 # INT* optional, out
): int32 {.importc: "LsaCallAuthenticationPackage", stdcall, dynlib: "SECUR32.dll".}pragma(lib, "secur32");
extern(Windows)
int LsaCallAuthenticationPackage(
void* LsaHandle, // HANDLE
uint AuthenticationPackage, // DWORD
void* ProtocolSubmitBuffer, // void*
uint SubmitBufferLength, // DWORD
void** ProtocolReturnBuffer, // void** optional, out
uint* ReturnBufferLength, // DWORD* optional, out
int* ProtocolStatus // INT* optional, out
);ccall((:LsaCallAuthenticationPackage, "SECUR32.dll"), stdcall, Int32,
(Ptr{Cvoid}, UInt32, Ptr{Cvoid}, UInt32, Ptr{Cvoid}, Ptr{UInt32}, Ptr{Int32}),
LsaHandle, AuthenticationPackage, ProtocolSubmitBuffer, SubmitBufferLength, ProtocolReturnBuffer, ReturnBufferLength, ProtocolStatus)
# LsaHandle : HANDLE -> Ptr{Cvoid}
# AuthenticationPackage : DWORD -> UInt32
# ProtocolSubmitBuffer : void* -> Ptr{Cvoid}
# SubmitBufferLength : DWORD -> UInt32
# ProtocolReturnBuffer : void** optional, out -> Ptr{Cvoid}
# ReturnBufferLength : DWORD* optional, out -> Ptr{UInt32}
# ProtocolStatus : INT* optional, out -> Ptr{Int32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t LsaCallAuthenticationPackage(
void* LsaHandle,
uint32_t AuthenticationPackage,
void* ProtocolSubmitBuffer,
uint32_t SubmitBufferLength,
void** ProtocolReturnBuffer,
uint32_t* ReturnBufferLength,
int32_t* ProtocolStatus);
]]
local secur32 = ffi.load("secur32")
-- secur32.LsaCallAuthenticationPackage(LsaHandle, AuthenticationPackage, ProtocolSubmitBuffer, SubmitBufferLength, ProtocolReturnBuffer, ReturnBufferLength, ProtocolStatus)
-- LsaHandle : HANDLE
-- AuthenticationPackage : DWORD
-- ProtocolSubmitBuffer : void*
-- SubmitBufferLength : DWORD
-- ProtocolReturnBuffer : void** optional, out
-- ReturnBufferLength : DWORD* optional, out
-- ProtocolStatus : INT* optional, out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('SECUR32.dll');
const LsaCallAuthenticationPackage = lib.func('__stdcall', 'LsaCallAuthenticationPackage', 'int32_t', ['void *', 'uint32_t', 'void *', 'uint32_t', 'void *', 'uint32_t *', 'int32_t *']);
// LsaCallAuthenticationPackage(LsaHandle, AuthenticationPackage, ProtocolSubmitBuffer, SubmitBufferLength, ProtocolReturnBuffer, ReturnBufferLength, ProtocolStatus)
// LsaHandle : HANDLE -> 'void *'
// AuthenticationPackage : DWORD -> 'uint32_t'
// ProtocolSubmitBuffer : void* -> 'void *'
// SubmitBufferLength : DWORD -> 'uint32_t'
// ProtocolReturnBuffer : void** optional, out -> 'void *'
// ReturnBufferLength : DWORD* optional, out -> 'uint32_t *'
// ProtocolStatus : INT* optional, out -> 'int32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("SECUR32.dll", {
LsaCallAuthenticationPackage: { parameters: ["pointer", "u32", "pointer", "u32", "pointer", "pointer", "pointer"], result: "i32" },
});
// lib.symbols.LsaCallAuthenticationPackage(LsaHandle, AuthenticationPackage, ProtocolSubmitBuffer, SubmitBufferLength, ProtocolReturnBuffer, ReturnBufferLength, ProtocolStatus)
// LsaHandle : HANDLE -> "pointer"
// AuthenticationPackage : DWORD -> "u32"
// ProtocolSubmitBuffer : void* -> "pointer"
// SubmitBufferLength : DWORD -> "u32"
// ProtocolReturnBuffer : void** optional, out -> "pointer"
// ReturnBufferLength : DWORD* optional, out -> "pointer"
// ProtocolStatus : INT* optional, out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t LsaCallAuthenticationPackage(
void* LsaHandle,
uint32_t AuthenticationPackage,
void* ProtocolSubmitBuffer,
uint32_t SubmitBufferLength,
void** ProtocolReturnBuffer,
uint32_t* ReturnBufferLength,
int32_t* ProtocolStatus);
C, "SECUR32.dll");
// $ffi->LsaCallAuthenticationPackage(LsaHandle, AuthenticationPackage, ProtocolSubmitBuffer, SubmitBufferLength, ProtocolReturnBuffer, ReturnBufferLength, ProtocolStatus);
// LsaHandle : HANDLE
// AuthenticationPackage : DWORD
// ProtocolSubmitBuffer : void*
// SubmitBufferLength : DWORD
// ProtocolReturnBuffer : void** optional, out
// ReturnBufferLength : DWORD* optional, out
// ProtocolStatus : INT* optional, 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 Secur32 extends StdCallLibrary {
Secur32 INSTANCE = Native.load("secur32", Secur32.class);
int LsaCallAuthenticationPackage(
Pointer LsaHandle, // HANDLE
int AuthenticationPackage, // DWORD
Pointer ProtocolSubmitBuffer, // void*
int SubmitBufferLength, // DWORD
Pointer ProtocolReturnBuffer, // void** optional, out
IntByReference ReturnBufferLength, // DWORD* optional, out
IntByReference ProtocolStatus // INT* optional, out
);
}@[Link("secur32")]
lib LibSECUR32
fun LsaCallAuthenticationPackage = LsaCallAuthenticationPackage(
LsaHandle : Void*, # HANDLE
AuthenticationPackage : UInt32, # DWORD
ProtocolSubmitBuffer : Void*, # void*
SubmitBufferLength : UInt32, # DWORD
ProtocolReturnBuffer : Void**, # void** optional, out
ReturnBufferLength : UInt32*, # DWORD* optional, out
ProtocolStatus : Int32* # INT* optional, out
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef LsaCallAuthenticationPackageNative = Int32 Function(Pointer<Void>, Uint32, Pointer<Void>, Uint32, Pointer<Void>, Pointer<Uint32>, Pointer<Int32>);
typedef LsaCallAuthenticationPackageDart = int Function(Pointer<Void>, int, Pointer<Void>, int, Pointer<Void>, Pointer<Uint32>, Pointer<Int32>);
final LsaCallAuthenticationPackage = DynamicLibrary.open('SECUR32.dll')
.lookupFunction<LsaCallAuthenticationPackageNative, LsaCallAuthenticationPackageDart>('LsaCallAuthenticationPackage');
// LsaHandle : HANDLE -> Pointer<Void>
// AuthenticationPackage : DWORD -> Uint32
// ProtocolSubmitBuffer : void* -> Pointer<Void>
// SubmitBufferLength : DWORD -> Uint32
// ProtocolReturnBuffer : void** optional, out -> Pointer<Void>
// ReturnBufferLength : DWORD* optional, out -> Pointer<Uint32>
// ProtocolStatus : INT* optional, out -> Pointer<Int32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function LsaCallAuthenticationPackage(
LsaHandle: THandle; // HANDLE
AuthenticationPackage: DWORD; // DWORD
ProtocolSubmitBuffer: Pointer; // void*
SubmitBufferLength: DWORD; // DWORD
ProtocolReturnBuffer: Pointer; // void** optional, out
ReturnBufferLength: Pointer; // DWORD* optional, out
ProtocolStatus: Pointer // INT* optional, out
): Integer; stdcall;
external 'SECUR32.dll' name 'LsaCallAuthenticationPackage';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "LsaCallAuthenticationPackage"
c_LsaCallAuthenticationPackage :: Ptr () -> Word32 -> Ptr () -> Word32 -> Ptr () -> Ptr Word32 -> Ptr Int32 -> IO Int32
-- LsaHandle : HANDLE -> Ptr ()
-- AuthenticationPackage : DWORD -> Word32
-- ProtocolSubmitBuffer : void* -> Ptr ()
-- SubmitBufferLength : DWORD -> Word32
-- ProtocolReturnBuffer : void** optional, out -> Ptr ()
-- ReturnBufferLength : DWORD* optional, out -> Ptr Word32
-- ProtocolStatus : INT* optional, out -> Ptr Int32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let lsacallauthenticationpackage =
foreign "LsaCallAuthenticationPackage"
((ptr void) @-> uint32_t @-> (ptr void) @-> uint32_t @-> (ptr void) @-> (ptr uint32_t) @-> (ptr int32_t) @-> returning int32_t)
(* LsaHandle : HANDLE -> (ptr void) *)
(* AuthenticationPackage : DWORD -> uint32_t *)
(* ProtocolSubmitBuffer : void* -> (ptr void) *)
(* SubmitBufferLength : DWORD -> uint32_t *)
(* ProtocolReturnBuffer : void** optional, out -> (ptr void) *)
(* ReturnBufferLength : DWORD* optional, out -> (ptr uint32_t) *)
(* ProtocolStatus : INT* optional, out -> (ptr int32_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library secur32 (t "SECUR32.dll"))
(cffi:use-foreign-library secur32)
(cffi:defcfun ("LsaCallAuthenticationPackage" lsa-call-authentication-package :convention :stdcall) :int32
(lsa-handle :pointer) ; HANDLE
(authentication-package :uint32) ; DWORD
(protocol-submit-buffer :pointer) ; void*
(submit-buffer-length :uint32) ; DWORD
(protocol-return-buffer :pointer) ; void** optional, out
(return-buffer-length :pointer) ; DWORD* optional, out
(protocol-status :pointer)) ; INT* optional, out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $LsaCallAuthenticationPackage = Win32::API::More->new('SECUR32',
'int LsaCallAuthenticationPackage(HANDLE LsaHandle, DWORD AuthenticationPackage, LPVOID ProtocolSubmitBuffer, DWORD SubmitBufferLength, LPVOID ProtocolReturnBuffer, LPVOID ReturnBufferLength, LPVOID ProtocolStatus)');
# my $ret = $LsaCallAuthenticationPackage->Call($LsaHandle, $AuthenticationPackage, $ProtocolSubmitBuffer, $SubmitBufferLength, $ProtocolReturnBuffer, $ReturnBufferLength, $ProtocolStatus);
# LsaHandle : HANDLE -> HANDLE
# AuthenticationPackage : DWORD -> DWORD
# ProtocolSubmitBuffer : void* -> LPVOID
# SubmitBufferLength : DWORD -> DWORD
# ProtocolReturnBuffer : void** optional, out -> LPVOID
# ReturnBufferLength : DWORD* optional, out -> LPVOID
# ProtocolStatus : INT* optional, out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
- f LsaFreeReturnBuffer — LSA関数が返したバッファのメモリを解放する。
- f LsaLookupAuthenticationPackage — 名前から認証パッケージの識別子を取得する。
- f LsaNtStatusToWinError — NTSTATUSコードを対応するWin32エラーコードへ変換する。