ホーム › Security.Authentication.Identity › SaslInitializeSecurityContextW
SaslInitializeSecurityContextW
関数SASL用クライアント側セキュリティコンテキストを初期化する(Unicode版)。
シグネチャ
// SECUR32.dll (Unicode / -W)
#include <windows.h>
HRESULT SaslInitializeSecurityContextW(
SecHandle* phCredential, // optional
SecHandle* phContext, // optional
LPWSTR pszTargetName, // optional
ISC_REQ_FLAGS fContextReq,
DWORD Reserved1,
DWORD TargetDataRep,
SecBufferDesc* pInput, // optional
DWORD Reserved2,
SecHandle* phNewContext, // optional
SecBufferDesc* pOutput, // optional
DWORD* pfContextAttr,
LONGLONG* ptsExpiry // optional
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| phCredential | SecHandle* | inoptional | AcquireCredentialsHandleで取得した資格情報ハンドルへのポインタ。 |
| phContext | SecHandle* | inoptional | 継続中のセキュリティコンテキストハンドルへのポインタ。初回呼び出し時はNULL。 |
| pszTargetName | LPWSTR | inoptional | 認証対象のターゲット名を示すワイド文字列。 |
| fContextReq | ISC_REQ_FLAGS | in | コンテキストに要求する属性を示すISC_REQ_FLAGSフラグ。 |
| Reserved1 | DWORD | in | 予約済み。0を指定する。 |
| TargetDataRep | DWORD | in | ターゲットのデータ表現形式を示す値(SECURITY_NATIVE_DREP等)。 |
| pInput | SecBufferDesc* | inoptional | サーバーから受信した入力トークンを保持するSecBufferDescへのポインタ。初回はNULL。 |
| Reserved2 | DWORD | in | 予約済み。0を指定する。 |
| phNewContext | SecHandle* | inoutoptional | 出力。新規または更新されたセキュリティコンテキストハンドルを受け取るポインタ。 |
| pOutput | SecBufferDesc* | inoutoptional | 出力。サーバーへ送信する出力トークンを受け取るSecBufferDescへのポインタ。 |
| pfContextAttr | DWORD* | out | 出力。確立されたコンテキストの属性フラグを受け取るDWORDへのポインタ。 |
| ptsExpiry | LONGLONG* | outoptional | 出力。コンテキストの有効期限を受け取るポインタ。NULL可。 |
戻り値の型: HRESULT
各言語での呼び出し定義
// SECUR32.dll (Unicode / -W)
#include <windows.h>
HRESULT SaslInitializeSecurityContextW(
SecHandle* phCredential, // optional
SecHandle* phContext, // optional
LPWSTR pszTargetName, // optional
ISC_REQ_FLAGS fContextReq,
DWORD Reserved1,
DWORD TargetDataRep,
SecBufferDesc* pInput, // optional
DWORD Reserved2,
SecHandle* phNewContext, // optional
SecBufferDesc* pOutput, // optional
DWORD* pfContextAttr,
LONGLONG* ptsExpiry // optional
);[DllImport("SECUR32.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern int SaslInitializeSecurityContextW(
IntPtr phCredential, // SecHandle* optional
IntPtr phContext, // SecHandle* optional
[MarshalAs(UnmanagedType.LPWStr)] string pszTargetName, // LPWSTR optional
uint fContextReq, // ISC_REQ_FLAGS
uint Reserved1, // DWORD
uint TargetDataRep, // DWORD
IntPtr pInput, // SecBufferDesc* optional
uint Reserved2, // DWORD
IntPtr phNewContext, // SecHandle* optional, in/out
IntPtr pOutput, // SecBufferDesc* optional, in/out
out uint pfContextAttr, // DWORD* out
IntPtr ptsExpiry // LONGLONG* optional, out
);<DllImport("SECUR32.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function SaslInitializeSecurityContextW(
phCredential As IntPtr, ' SecHandle* optional
phContext As IntPtr, ' SecHandle* optional
<MarshalAs(UnmanagedType.LPWStr)> pszTargetName As String, ' LPWSTR optional
fContextReq As UInteger, ' ISC_REQ_FLAGS
Reserved1 As UInteger, ' DWORD
TargetDataRep As UInteger, ' DWORD
pInput As IntPtr, ' SecBufferDesc* optional
Reserved2 As UInteger, ' DWORD
phNewContext As IntPtr, ' SecHandle* optional, in/out
pOutput As IntPtr, ' SecBufferDesc* optional, in/out
<Out> ByRef pfContextAttr As UInteger, ' DWORD* out
ptsExpiry As IntPtr ' LONGLONG* optional, out
) As Integer
End Function' phCredential : SecHandle* optional
' phContext : SecHandle* optional
' pszTargetName : LPWSTR optional
' fContextReq : ISC_REQ_FLAGS
' Reserved1 : DWORD
' TargetDataRep : DWORD
' pInput : SecBufferDesc* optional
' Reserved2 : DWORD
' phNewContext : SecHandle* optional, in/out
' pOutput : SecBufferDesc* optional, in/out
' pfContextAttr : DWORD* out
' ptsExpiry : LONGLONG* optional, out
Declare PtrSafe Function SaslInitializeSecurityContextW Lib "secur32" ( _
ByVal phCredential As LongPtr, _
ByVal phContext As LongPtr, _
ByVal pszTargetName As LongPtr, _
ByVal fContextReq As Long, _
ByVal Reserved1 As Long, _
ByVal TargetDataRep As Long, _
ByVal pInput As LongPtr, _
ByVal Reserved2 As Long, _
ByVal phNewContext As LongPtr, _
ByVal pOutput As LongPtr, _
ByRef pfContextAttr As Long, _
ByVal ptsExpiry 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
SaslInitializeSecurityContextW = ctypes.windll.secur32.SaslInitializeSecurityContextW
SaslInitializeSecurityContextW.restype = ctypes.c_int
SaslInitializeSecurityContextW.argtypes = [
ctypes.c_void_p, # phCredential : SecHandle* optional
ctypes.c_void_p, # phContext : SecHandle* optional
wintypes.LPCWSTR, # pszTargetName : LPWSTR optional
wintypes.DWORD, # fContextReq : ISC_REQ_FLAGS
wintypes.DWORD, # Reserved1 : DWORD
wintypes.DWORD, # TargetDataRep : DWORD
ctypes.c_void_p, # pInput : SecBufferDesc* optional
wintypes.DWORD, # Reserved2 : DWORD
ctypes.c_void_p, # phNewContext : SecHandle* optional, in/out
ctypes.c_void_p, # pOutput : SecBufferDesc* optional, in/out
ctypes.POINTER(wintypes.DWORD), # pfContextAttr : DWORD* out
ctypes.POINTER(ctypes.c_longlong), # ptsExpiry : LONGLONG* optional, out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('SECUR32.dll')
SaslInitializeSecurityContextW = Fiddle::Function.new(
lib['SaslInitializeSecurityContextW'],
[
Fiddle::TYPE_VOIDP, # phCredential : SecHandle* optional
Fiddle::TYPE_VOIDP, # phContext : SecHandle* optional
Fiddle::TYPE_VOIDP, # pszTargetName : LPWSTR optional
-Fiddle::TYPE_INT, # fContextReq : ISC_REQ_FLAGS
-Fiddle::TYPE_INT, # Reserved1 : DWORD
-Fiddle::TYPE_INT, # TargetDataRep : DWORD
Fiddle::TYPE_VOIDP, # pInput : SecBufferDesc* optional
-Fiddle::TYPE_INT, # Reserved2 : DWORD
Fiddle::TYPE_VOIDP, # phNewContext : SecHandle* optional, in/out
Fiddle::TYPE_VOIDP, # pOutput : SecBufferDesc* optional, in/out
Fiddle::TYPE_VOIDP, # pfContextAttr : DWORD* out
Fiddle::TYPE_VOIDP, # ptsExpiry : LONGLONG* optional, out
],
Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "secur32")]
extern "system" {
fn SaslInitializeSecurityContextW(
phCredential: *mut SecHandle, // SecHandle* optional
phContext: *mut SecHandle, // SecHandle* optional
pszTargetName: *mut u16, // LPWSTR optional
fContextReq: u32, // ISC_REQ_FLAGS
Reserved1: u32, // DWORD
TargetDataRep: u32, // DWORD
pInput: *mut SecBufferDesc, // SecBufferDesc* optional
Reserved2: u32, // DWORD
phNewContext: *mut SecHandle, // SecHandle* optional, in/out
pOutput: *mut SecBufferDesc, // SecBufferDesc* optional, in/out
pfContextAttr: *mut u32, // DWORD* out
ptsExpiry: *mut i64 // LONGLONG* optional, out
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("SECUR32.dll", CharSet = CharSet.Unicode)]
public static extern int SaslInitializeSecurityContextW(IntPtr phCredential, IntPtr phContext, [MarshalAs(UnmanagedType.LPWStr)] string pszTargetName, uint fContextReq, uint Reserved1, uint TargetDataRep, IntPtr pInput, uint Reserved2, IntPtr phNewContext, IntPtr pOutput, out uint pfContextAttr, IntPtr ptsExpiry);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SECUR32_SaslInitializeSecurityContextW' -Namespace Win32 -PassThru
# $api::SaslInitializeSecurityContextW(phCredential, phContext, pszTargetName, fContextReq, Reserved1, TargetDataRep, pInput, Reserved2, phNewContext, pOutput, pfContextAttr, ptsExpiry)#uselib "SECUR32.dll"
#func global SaslInitializeSecurityContextW "SaslInitializeSecurityContextW" wptr, wptr, wptr, wptr, wptr, wptr, wptr, wptr, wptr, wptr, wptr, wptr
; SaslInitializeSecurityContextW varptr(phCredential), varptr(phContext), pszTargetName, fContextReq, Reserved1, TargetDataRep, varptr(pInput), Reserved2, varptr(phNewContext), varptr(pOutput), varptr(pfContextAttr), varptr(ptsExpiry) ; 戻り値は stat
; phCredential : SecHandle* optional -> "wptr"
; phContext : SecHandle* optional -> "wptr"
; pszTargetName : LPWSTR optional -> "wptr"
; fContextReq : ISC_REQ_FLAGS -> "wptr"
; Reserved1 : DWORD -> "wptr"
; TargetDataRep : DWORD -> "wptr"
; pInput : SecBufferDesc* optional -> "wptr"
; Reserved2 : DWORD -> "wptr"
; phNewContext : SecHandle* optional, in/out -> "wptr"
; pOutput : SecBufferDesc* optional, in/out -> "wptr"
; pfContextAttr : DWORD* out -> "wptr"
; ptsExpiry : LONGLONG* optional, out -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "SECUR32.dll" #cfunc global SaslInitializeSecurityContextW "SaslInitializeSecurityContextW" var, var, wstr, int, int, int, var, int, var, var, var, var ; res = SaslInitializeSecurityContextW(phCredential, phContext, pszTargetName, fContextReq, Reserved1, TargetDataRep, pInput, Reserved2, phNewContext, pOutput, pfContextAttr, ptsExpiry) ; phCredential : SecHandle* optional -> "var" ; phContext : SecHandle* optional -> "var" ; pszTargetName : LPWSTR optional -> "wstr" ; fContextReq : ISC_REQ_FLAGS -> "int" ; Reserved1 : DWORD -> "int" ; TargetDataRep : DWORD -> "int" ; pInput : SecBufferDesc* optional -> "var" ; Reserved2 : DWORD -> "int" ; phNewContext : SecHandle* optional, in/out -> "var" ; pOutput : SecBufferDesc* optional, in/out -> "var" ; pfContextAttr : DWORD* out -> "var" ; ptsExpiry : LONGLONG* optional, out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "SECUR32.dll" #cfunc global SaslInitializeSecurityContextW "SaslInitializeSecurityContextW" sptr, sptr, wstr, int, int, int, sptr, int, sptr, sptr, sptr, sptr ; res = SaslInitializeSecurityContextW(varptr(phCredential), varptr(phContext), pszTargetName, fContextReq, Reserved1, TargetDataRep, varptr(pInput), Reserved2, varptr(phNewContext), varptr(pOutput), varptr(pfContextAttr), varptr(ptsExpiry)) ; phCredential : SecHandle* optional -> "sptr" ; phContext : SecHandle* optional -> "sptr" ; pszTargetName : LPWSTR optional -> "wstr" ; fContextReq : ISC_REQ_FLAGS -> "int" ; Reserved1 : DWORD -> "int" ; TargetDataRep : DWORD -> "int" ; pInput : SecBufferDesc* optional -> "sptr" ; Reserved2 : DWORD -> "int" ; phNewContext : SecHandle* optional, in/out -> "sptr" ; pOutput : SecBufferDesc* optional, in/out -> "sptr" ; pfContextAttr : DWORD* out -> "sptr" ; ptsExpiry : LONGLONG* optional, out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; HRESULT SaslInitializeSecurityContextW(SecHandle* phCredential, SecHandle* phContext, LPWSTR pszTargetName, ISC_REQ_FLAGS fContextReq, DWORD Reserved1, DWORD TargetDataRep, SecBufferDesc* pInput, DWORD Reserved2, SecHandle* phNewContext, SecBufferDesc* pOutput, DWORD* pfContextAttr, LONGLONG* ptsExpiry) #uselib "SECUR32.dll" #cfunc global SaslInitializeSecurityContextW "SaslInitializeSecurityContextW" var, var, wstr, int, int, int, var, int, var, var, var, var ; res = SaslInitializeSecurityContextW(phCredential, phContext, pszTargetName, fContextReq, Reserved1, TargetDataRep, pInput, Reserved2, phNewContext, pOutput, pfContextAttr, ptsExpiry) ; phCredential : SecHandle* optional -> "var" ; phContext : SecHandle* optional -> "var" ; pszTargetName : LPWSTR optional -> "wstr" ; fContextReq : ISC_REQ_FLAGS -> "int" ; Reserved1 : DWORD -> "int" ; TargetDataRep : DWORD -> "int" ; pInput : SecBufferDesc* optional -> "var" ; Reserved2 : DWORD -> "int" ; phNewContext : SecHandle* optional, in/out -> "var" ; pOutput : SecBufferDesc* optional, in/out -> "var" ; pfContextAttr : DWORD* out -> "var" ; ptsExpiry : LONGLONG* optional, out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; HRESULT SaslInitializeSecurityContextW(SecHandle* phCredential, SecHandle* phContext, LPWSTR pszTargetName, ISC_REQ_FLAGS fContextReq, DWORD Reserved1, DWORD TargetDataRep, SecBufferDesc* pInput, DWORD Reserved2, SecHandle* phNewContext, SecBufferDesc* pOutput, DWORD* pfContextAttr, LONGLONG* ptsExpiry) #uselib "SECUR32.dll" #cfunc global SaslInitializeSecurityContextW "SaslInitializeSecurityContextW" intptr, intptr, wstr, int, int, int, intptr, int, intptr, intptr, intptr, intptr ; res = SaslInitializeSecurityContextW(varptr(phCredential), varptr(phContext), pszTargetName, fContextReq, Reserved1, TargetDataRep, varptr(pInput), Reserved2, varptr(phNewContext), varptr(pOutput), varptr(pfContextAttr), varptr(ptsExpiry)) ; phCredential : SecHandle* optional -> "intptr" ; phContext : SecHandle* optional -> "intptr" ; pszTargetName : LPWSTR optional -> "wstr" ; fContextReq : ISC_REQ_FLAGS -> "int" ; Reserved1 : DWORD -> "int" ; TargetDataRep : DWORD -> "int" ; pInput : SecBufferDesc* optional -> "intptr" ; Reserved2 : DWORD -> "int" ; phNewContext : SecHandle* optional, in/out -> "intptr" ; pOutput : SecBufferDesc* optional, in/out -> "intptr" ; pfContextAttr : DWORD* out -> "intptr" ; ptsExpiry : LONGLONG* optional, out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
secur32 = windows.NewLazySystemDLL("SECUR32.dll")
procSaslInitializeSecurityContextW = secur32.NewProc("SaslInitializeSecurityContextW")
)
// phCredential (SecHandle* optional), phContext (SecHandle* optional), pszTargetName (LPWSTR optional), fContextReq (ISC_REQ_FLAGS), Reserved1 (DWORD), TargetDataRep (DWORD), pInput (SecBufferDesc* optional), Reserved2 (DWORD), phNewContext (SecHandle* optional, in/out), pOutput (SecBufferDesc* optional, in/out), pfContextAttr (DWORD* out), ptsExpiry (LONGLONG* optional, out)
r1, _, err := procSaslInitializeSecurityContextW.Call(
uintptr(phCredential),
uintptr(phContext),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pszTargetName))),
uintptr(fContextReq),
uintptr(Reserved1),
uintptr(TargetDataRep),
uintptr(pInput),
uintptr(Reserved2),
uintptr(phNewContext),
uintptr(pOutput),
uintptr(pfContextAttr),
uintptr(ptsExpiry),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // HRESULTfunction SaslInitializeSecurityContextW(
phCredential: Pointer; // SecHandle* optional
phContext: Pointer; // SecHandle* optional
pszTargetName: PWideChar; // LPWSTR optional
fContextReq: DWORD; // ISC_REQ_FLAGS
Reserved1: DWORD; // DWORD
TargetDataRep: DWORD; // DWORD
pInput: Pointer; // SecBufferDesc* optional
Reserved2: DWORD; // DWORD
phNewContext: Pointer; // SecHandle* optional, in/out
pOutput: Pointer; // SecBufferDesc* optional, in/out
pfContextAttr: Pointer; // DWORD* out
ptsExpiry: Pointer // LONGLONG* optional, out
): Integer; stdcall;
external 'SECUR32.dll' name 'SaslInitializeSecurityContextW';result := DllCall("SECUR32\SaslInitializeSecurityContextW"
, "Ptr", phCredential ; SecHandle* optional
, "Ptr", phContext ; SecHandle* optional
, "WStr", pszTargetName ; LPWSTR optional
, "UInt", fContextReq ; ISC_REQ_FLAGS
, "UInt", Reserved1 ; DWORD
, "UInt", TargetDataRep ; DWORD
, "Ptr", pInput ; SecBufferDesc* optional
, "UInt", Reserved2 ; DWORD
, "Ptr", phNewContext ; SecHandle* optional, in/out
, "Ptr", pOutput ; SecBufferDesc* optional, in/out
, "Ptr", pfContextAttr ; DWORD* out
, "Ptr", ptsExpiry ; LONGLONG* optional, out
, "Int") ; return: HRESULT●SaslInitializeSecurityContextW(phCredential, phContext, pszTargetName, fContextReq, Reserved1, TargetDataRep, pInput, Reserved2, phNewContext, pOutput, pfContextAttr, ptsExpiry) = DLL("SECUR32.dll", "int SaslInitializeSecurityContextW(void*, void*, char*, dword, dword, dword, void*, dword, void*, void*, void*, void*)")
# 呼び出し: SaslInitializeSecurityContextW(phCredential, phContext, pszTargetName, fContextReq, Reserved1, TargetDataRep, pInput, Reserved2, phNewContext, pOutput, pfContextAttr, ptsExpiry)
# phCredential : SecHandle* optional -> "void*"
# phContext : SecHandle* optional -> "void*"
# pszTargetName : LPWSTR optional -> "char*"
# fContextReq : ISC_REQ_FLAGS -> "dword"
# Reserved1 : DWORD -> "dword"
# TargetDataRep : DWORD -> "dword"
# pInput : SecBufferDesc* optional -> "void*"
# Reserved2 : DWORD -> "dword"
# phNewContext : SecHandle* optional, in/out -> "void*"
# pOutput : SecBufferDesc* optional, in/out -> "void*"
# pfContextAttr : DWORD* out -> "void*"
# ptsExpiry : LONGLONG* optional, out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。const std = @import("std");
extern "secur32" fn SaslInitializeSecurityContextW(
phCredential: [*c]SecHandle, // SecHandle* optional
phContext: [*c]SecHandle, // SecHandle* optional
pszTargetName: [*c]const u16, // LPWSTR optional
fContextReq: u32, // ISC_REQ_FLAGS
Reserved1: u32, // DWORD
TargetDataRep: u32, // DWORD
pInput: [*c]SecBufferDesc, // SecBufferDesc* optional
Reserved2: u32, // DWORD
phNewContext: [*c]SecHandle, // SecHandle* optional, in/out
pOutput: [*c]SecBufferDesc, // SecBufferDesc* optional, in/out
pfContextAttr: [*c]u32, // DWORD* out
ptsExpiry: [*c]i64 // LONGLONG* optional, out
) callconv(std.os.windows.WINAPI) i32;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。proc SaslInitializeSecurityContextW(
phCredential: ptr SecHandle, # SecHandle* optional
phContext: ptr SecHandle, # SecHandle* optional
pszTargetName: WideCString, # LPWSTR optional
fContextReq: uint32, # ISC_REQ_FLAGS
Reserved1: uint32, # DWORD
TargetDataRep: uint32, # DWORD
pInput: ptr SecBufferDesc, # SecBufferDesc* optional
Reserved2: uint32, # DWORD
phNewContext: ptr SecHandle, # SecHandle* optional, in/out
pOutput: ptr SecBufferDesc, # SecBufferDesc* optional, in/out
pfContextAttr: ptr uint32, # DWORD* out
ptsExpiry: ptr int64 # LONGLONG* optional, out
): int32 {.importc: "SaslInitializeSecurityContextW", stdcall, dynlib: "SECUR32.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。pragma(lib, "secur32");
extern(Windows)
int SaslInitializeSecurityContextW(
SecHandle* phCredential, // SecHandle* optional
SecHandle* phContext, // SecHandle* optional
const(wchar)* pszTargetName, // LPWSTR optional
uint fContextReq, // ISC_REQ_FLAGS
uint Reserved1, // DWORD
uint TargetDataRep, // DWORD
SecBufferDesc* pInput, // SecBufferDesc* optional
uint Reserved2, // DWORD
SecHandle* phNewContext, // SecHandle* optional, in/out
SecBufferDesc* pOutput, // SecBufferDesc* optional, in/out
uint* pfContextAttr, // DWORD* out
long* ptsExpiry // LONGLONG* optional, out
);ccall((:SaslInitializeSecurityContextW, "SECUR32.dll"), stdcall, Int32,
(Ptr{SecHandle}, Ptr{SecHandle}, Cwstring, UInt32, UInt32, UInt32, Ptr{SecBufferDesc}, UInt32, Ptr{SecHandle}, Ptr{SecBufferDesc}, Ptr{UInt32}, Ptr{Int64}),
phCredential, phContext, pszTargetName, fContextReq, Reserved1, TargetDataRep, pInput, Reserved2, phNewContext, pOutput, pfContextAttr, ptsExpiry)
# phCredential : SecHandle* optional -> Ptr{SecHandle}
# phContext : SecHandle* optional -> Ptr{SecHandle}
# pszTargetName : LPWSTR optional -> Cwstring
# fContextReq : ISC_REQ_FLAGS -> UInt32
# Reserved1 : DWORD -> UInt32
# TargetDataRep : DWORD -> UInt32
# pInput : SecBufferDesc* optional -> Ptr{SecBufferDesc}
# Reserved2 : DWORD -> UInt32
# phNewContext : SecHandle* optional, in/out -> Ptr{SecHandle}
# pOutput : SecBufferDesc* optional, in/out -> Ptr{SecBufferDesc}
# pfContextAttr : DWORD* out -> Ptr{UInt32}
# ptsExpiry : LONGLONG* optional, out -> Ptr{Int64}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。local ffi = require("ffi")
ffi.cdef[[
int32_t SaslInitializeSecurityContextW(
void* phCredential,
void* phContext,
const uint16_t* pszTargetName,
uint32_t fContextReq,
uint32_t Reserved1,
uint32_t TargetDataRep,
void* pInput,
uint32_t Reserved2,
void* phNewContext,
void* pOutput,
uint32_t* pfContextAttr,
int64_t* ptsExpiry);
]]
local secur32 = ffi.load("secur32")
-- secur32.SaslInitializeSecurityContextW(phCredential, phContext, pszTargetName, fContextReq, Reserved1, TargetDataRep, pInput, Reserved2, phNewContext, pOutput, pfContextAttr, ptsExpiry)
-- phCredential : SecHandle* optional
-- phContext : SecHandle* optional
-- pszTargetName : LPWSTR optional
-- fContextReq : ISC_REQ_FLAGS
-- Reserved1 : DWORD
-- TargetDataRep : DWORD
-- pInput : SecBufferDesc* optional
-- Reserved2 : DWORD
-- phNewContext : SecHandle* optional, in/out
-- pOutput : SecBufferDesc* optional, in/out
-- pfContextAttr : DWORD* out
-- ptsExpiry : LONGLONG* optional, out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
-- Unicode(-W): uint16_t* には UTF-16LE のバッファ(ffi.new("uint16_t[?]", ...))を渡す。const koffi = require('koffi');
const lib = koffi.load('SECUR32.dll');
const SaslInitializeSecurityContextW = lib.func('__stdcall', 'SaslInitializeSecurityContextW', 'int32_t', ['void *', 'void *', 'str16', 'uint32_t', 'uint32_t', 'uint32_t', 'void *', 'uint32_t', 'void *', 'void *', 'uint32_t *', 'int64_t *']);
// SaslInitializeSecurityContextW(phCredential, phContext, pszTargetName, fContextReq, Reserved1, TargetDataRep, pInput, Reserved2, phNewContext, pOutput, pfContextAttr, ptsExpiry)
// phCredential : SecHandle* optional -> 'void *'
// phContext : SecHandle* optional -> 'void *'
// pszTargetName : LPWSTR optional -> 'str16'
// fContextReq : ISC_REQ_FLAGS -> 'uint32_t'
// Reserved1 : DWORD -> 'uint32_t'
// TargetDataRep : DWORD -> 'uint32_t'
// pInput : SecBufferDesc* optional -> 'void *'
// Reserved2 : DWORD -> 'uint32_t'
// phNewContext : SecHandle* optional, in/out -> 'void *'
// pOutput : SecBufferDesc* optional, in/out -> 'void *'
// pfContextAttr : DWORD* out -> 'uint32_t *'
// ptsExpiry : LONGLONG* optional, out -> 'int64_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("SECUR32.dll", {
SaslInitializeSecurityContextW: { parameters: ["pointer", "pointer", "buffer", "u32", "u32", "u32", "pointer", "u32", "pointer", "pointer", "pointer", "pointer"], result: "i32" },
});
// lib.symbols.SaslInitializeSecurityContextW(phCredential, phContext, pszTargetName, fContextReq, Reserved1, TargetDataRep, pInput, Reserved2, phNewContext, pOutput, pfContextAttr, ptsExpiry)
// phCredential : SecHandle* optional -> "pointer"
// phContext : SecHandle* optional -> "pointer"
// pszTargetName : LPWSTR optional -> "buffer"
// fContextReq : ISC_REQ_FLAGS -> "u32"
// Reserved1 : DWORD -> "u32"
// TargetDataRep : DWORD -> "u32"
// pInput : SecBufferDesc* optional -> "pointer"
// Reserved2 : DWORD -> "u32"
// phNewContext : SecHandle* optional, in/out -> "pointer"
// pOutput : SecBufferDesc* optional, in/out -> "pointer"
// pfContextAttr : DWORD* out -> "pointer"
// ptsExpiry : LONGLONG* optional, out -> "pointer"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t SaslInitializeSecurityContextW(
void* phCredential,
void* phContext,
const uint16_t* pszTargetName,
uint32_t fContextReq,
uint32_t Reserved1,
uint32_t TargetDataRep,
void* pInput,
uint32_t Reserved2,
void* phNewContext,
void* pOutput,
uint32_t* pfContextAttr,
int64_t* ptsExpiry);
C, "SECUR32.dll");
// $ffi->SaslInitializeSecurityContextW(phCredential, phContext, pszTargetName, fContextReq, Reserved1, TargetDataRep, pInput, Reserved2, phNewContext, pOutput, pfContextAttr, ptsExpiry);
// phCredential : SecHandle* optional
// phContext : SecHandle* optional
// pszTargetName : LPWSTR optional
// fContextReq : ISC_REQ_FLAGS
// Reserved1 : DWORD
// TargetDataRep : DWORD
// pInput : SecBufferDesc* optional
// Reserved2 : DWORD
// phNewContext : SecHandle* optional, in/out
// pOutput : SecBufferDesc* optional, in/out
// pfContextAttr : DWORD* out
// ptsExpiry : LONGLONG* 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, W32APIOptions.UNICODE_OPTIONS);
int SaslInitializeSecurityContextW(
Pointer phCredential, // SecHandle* optional
Pointer phContext, // SecHandle* optional
WString pszTargetName, // LPWSTR optional
int fContextReq, // ISC_REQ_FLAGS
int Reserved1, // DWORD
int TargetDataRep, // DWORD
Pointer pInput, // SecBufferDesc* optional
int Reserved2, // DWORD
Pointer phNewContext, // SecHandle* optional, in/out
Pointer pOutput, // SecBufferDesc* optional, in/out
IntByReference pfContextAttr, // DWORD* out
LongByReference ptsExpiry // LONGLONG* optional, out
);
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。@[Link("secur32")]
lib LibSECUR32
fun SaslInitializeSecurityContextW = SaslInitializeSecurityContextW(
phCredential : SecHandle*, # SecHandle* optional
phContext : SecHandle*, # SecHandle* optional
pszTargetName : UInt16*, # LPWSTR optional
fContextReq : UInt32, # ISC_REQ_FLAGS
Reserved1 : UInt32, # DWORD
TargetDataRep : UInt32, # DWORD
pInput : SecBufferDesc*, # SecBufferDesc* optional
Reserved2 : UInt32, # DWORD
phNewContext : SecHandle*, # SecHandle* optional, in/out
pOutput : SecBufferDesc*, # SecBufferDesc* optional, in/out
pfContextAttr : UInt32*, # DWORD* out
ptsExpiry : Int64* # LONGLONG* 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 SaslInitializeSecurityContextWNative = Int32 Function(Pointer<Void>, Pointer<Void>, Pointer<Utf16>, Uint32, Uint32, Uint32, Pointer<Void>, Uint32, Pointer<Void>, Pointer<Void>, Pointer<Uint32>, Pointer<Int64>);
typedef SaslInitializeSecurityContextWDart = int Function(Pointer<Void>, Pointer<Void>, Pointer<Utf16>, int, int, int, Pointer<Void>, int, Pointer<Void>, Pointer<Void>, Pointer<Uint32>, Pointer<Int64>);
final SaslInitializeSecurityContextW = DynamicLibrary.open('SECUR32.dll')
.lookupFunction<SaslInitializeSecurityContextWNative, SaslInitializeSecurityContextWDart>('SaslInitializeSecurityContextW');
// phCredential : SecHandle* optional -> Pointer<Void>
// phContext : SecHandle* optional -> Pointer<Void>
// pszTargetName : LPWSTR optional -> Pointer<Utf16>
// fContextReq : ISC_REQ_FLAGS -> Uint32
// Reserved1 : DWORD -> Uint32
// TargetDataRep : DWORD -> Uint32
// pInput : SecBufferDesc* optional -> Pointer<Void>
// Reserved2 : DWORD -> Uint32
// phNewContext : SecHandle* optional, in/out -> Pointer<Void>
// pOutput : SecBufferDesc* optional, in/out -> Pointer<Void>
// pfContextAttr : DWORD* out -> Pointer<Uint32>
// ptsExpiry : LONGLONG* optional, out -> Pointer<Int64>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function SaslInitializeSecurityContextW(
phCredential: Pointer; // SecHandle* optional
phContext: Pointer; // SecHandle* optional
pszTargetName: PWideChar; // LPWSTR optional
fContextReq: DWORD; // ISC_REQ_FLAGS
Reserved1: DWORD; // DWORD
TargetDataRep: DWORD; // DWORD
pInput: Pointer; // SecBufferDesc* optional
Reserved2: DWORD; // DWORD
phNewContext: Pointer; // SecHandle* optional, in/out
pOutput: Pointer; // SecBufferDesc* optional, in/out
pfContextAttr: Pointer; // DWORD* out
ptsExpiry: Pointer // LONGLONG* optional, out
): Integer; stdcall;
external 'SECUR32.dll' name 'SaslInitializeSecurityContextW';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "SaslInitializeSecurityContextW"
c_SaslInitializeSecurityContextW :: Ptr () -> Ptr () -> CWString -> Word32 -> Word32 -> Word32 -> Ptr () -> Word32 -> Ptr () -> Ptr () -> Ptr Word32 -> Ptr Int64 -> IO Int32
-- phCredential : SecHandle* optional -> Ptr ()
-- phContext : SecHandle* optional -> Ptr ()
-- pszTargetName : LPWSTR optional -> CWString
-- fContextReq : ISC_REQ_FLAGS -> Word32
-- Reserved1 : DWORD -> Word32
-- TargetDataRep : DWORD -> Word32
-- pInput : SecBufferDesc* optional -> Ptr ()
-- Reserved2 : DWORD -> Word32
-- phNewContext : SecHandle* optional, in/out -> Ptr ()
-- pOutput : SecBufferDesc* optional, in/out -> Ptr ()
-- pfContextAttr : DWORD* out -> Ptr Word32
-- ptsExpiry : LONGLONG* optional, out -> Ptr Int64
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let saslinitializesecuritycontextw =
foreign "SaslInitializeSecurityContextW"
((ptr void) @-> (ptr void) @-> (ptr uint16_t) @-> uint32_t @-> uint32_t @-> uint32_t @-> (ptr void) @-> uint32_t @-> (ptr void) @-> (ptr void) @-> (ptr uint32_t) @-> (ptr int64_t) @-> returning int32_t)
(* phCredential : SecHandle* optional -> (ptr void) *)
(* phContext : SecHandle* optional -> (ptr void) *)
(* pszTargetName : LPWSTR optional -> (ptr uint16_t) *)
(* fContextReq : ISC_REQ_FLAGS -> uint32_t *)
(* Reserved1 : DWORD -> uint32_t *)
(* TargetDataRep : DWORD -> uint32_t *)
(* pInput : SecBufferDesc* optional -> (ptr void) *)
(* Reserved2 : DWORD -> uint32_t *)
(* phNewContext : SecHandle* optional, in/out -> (ptr void) *)
(* pOutput : SecBufferDesc* optional, in/out -> (ptr void) *)
(* pfContextAttr : DWORD* out -> (ptr uint32_t) *)
(* ptsExpiry : LONGLONG* optional, out -> (ptr int64_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library secur32 (t "SECUR32.dll"))
(cffi:use-foreign-library secur32)
(cffi:defcfun ("SaslInitializeSecurityContextW" sasl-initialize-security-context-w :convention :stdcall) :int32
(ph-credential :pointer) ; SecHandle* optional
(ph-context :pointer) ; SecHandle* optional
(psz-target-name (:string :encoding :utf-16le)) ; LPWSTR optional
(f-context-req :uint32) ; ISC_REQ_FLAGS
(reserved1 :uint32) ; DWORD
(target-data-rep :uint32) ; DWORD
(p-input :pointer) ; SecBufferDesc* optional
(reserved2 :uint32) ; DWORD
(ph-new-context :pointer) ; SecHandle* optional, in/out
(p-output :pointer) ; SecBufferDesc* optional, in/out
(pf-context-attr :pointer) ; DWORD* out
(pts-expiry :pointer)) ; LONGLONG* optional, out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $SaslInitializeSecurityContextW = Win32::API::More->new('SECUR32',
'int SaslInitializeSecurityContextW(LPVOID phCredential, LPVOID phContext, LPCWSTR pszTargetName, DWORD fContextReq, DWORD Reserved1, DWORD TargetDataRep, LPVOID pInput, DWORD Reserved2, LPVOID phNewContext, LPVOID pOutput, LPVOID pfContextAttr, LPVOID ptsExpiry)');
# my $ret = $SaslInitializeSecurityContextW->Call($phCredential, $phContext, $pszTargetName, $fContextReq, $Reserved1, $TargetDataRep, $pInput, $Reserved2, $phNewContext, $pOutput, $pfContextAttr, $ptsExpiry);
# phCredential : SecHandle* optional -> LPVOID
# phContext : SecHandle* optional -> LPVOID
# pszTargetName : LPWSTR optional -> LPCWSTR
# fContextReq : ISC_REQ_FLAGS -> DWORD
# Reserved1 : DWORD -> DWORD
# TargetDataRep : DWORD -> DWORD
# pInput : SecBufferDesc* optional -> LPVOID
# Reserved2 : DWORD -> DWORD
# phNewContext : SecHandle* optional, in/out -> LPVOID
# pOutput : SecBufferDesc* optional, in/out -> LPVOID
# pfContextAttr : DWORD* out -> LPVOID
# ptsExpiry : LONGLONG* optional, out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。関連項目
文字セット違い
- f SaslInitializeSecurityContextA (ANSI版) — SASL用クライアント側セキュリティコンテキストを初期化する(ANSI版)。