ホーム › Security.Authentication.Identity › SaslInitializeSecurityContextA
SaslInitializeSecurityContextA
関数SASL用クライアント側セキュリティコンテキストを初期化する(ANSI版)。
シグネチャ
// SECUR32.dll (ANSI / -A)
#include <windows.h>
HRESULT SaslInitializeSecurityContextA(
SecHandle* phCredential, // optional
SecHandle* phContext, // optional
LPSTR 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 | LPSTR | inoptional | 認証対象のターゲット名を示すANSI文字列。 |
| 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 (ANSI / -A)
#include <windows.h>
HRESULT SaslInitializeSecurityContextA(
SecHandle* phCredential, // optional
SecHandle* phContext, // optional
LPSTR 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.Ansi, ExactSpelling = true)]
static extern int SaslInitializeSecurityContextA(
IntPtr phCredential, // SecHandle* optional
IntPtr phContext, // SecHandle* optional
[MarshalAs(UnmanagedType.LPStr)] string pszTargetName, // LPSTR 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.Ansi, ExactSpelling:=True)>
Public Shared Function SaslInitializeSecurityContextA(
phCredential As IntPtr, ' SecHandle* optional
phContext As IntPtr, ' SecHandle* optional
<MarshalAs(UnmanagedType.LPStr)> pszTargetName As String, ' LPSTR 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 : LPSTR 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 SaslInitializeSecurityContextA Lib "secur32" ( _
ByVal phCredential As LongPtr, _
ByVal phContext As LongPtr, _
ByVal pszTargetName As String, _
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
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
SaslInitializeSecurityContextA = ctypes.windll.secur32.SaslInitializeSecurityContextA
SaslInitializeSecurityContextA.restype = ctypes.c_int
SaslInitializeSecurityContextA.argtypes = [
ctypes.c_void_p, # phCredential : SecHandle* optional
ctypes.c_void_p, # phContext : SecHandle* optional
wintypes.LPCSTR, # pszTargetName : LPSTR 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')
SaslInitializeSecurityContextA = Fiddle::Function.new(
lib['SaslInitializeSecurityContextA'],
[
Fiddle::TYPE_VOIDP, # phCredential : SecHandle* optional
Fiddle::TYPE_VOIDP, # phContext : SecHandle* optional
Fiddle::TYPE_VOIDP, # pszTargetName : LPSTR 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)#[link(name = "secur32")]
extern "system" {
fn SaslInitializeSecurityContextA(
phCredential: *mut SecHandle, // SecHandle* optional
phContext: *mut SecHandle, // SecHandle* optional
pszTargetName: *mut u8, // LPSTR 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.Ansi)]
public static extern int SaslInitializeSecurityContextA(IntPtr phCredential, IntPtr phContext, [MarshalAs(UnmanagedType.LPStr)] 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_SaslInitializeSecurityContextA' -Namespace Win32 -PassThru
# $api::SaslInitializeSecurityContextA(phCredential, phContext, pszTargetName, fContextReq, Reserved1, TargetDataRep, pInput, Reserved2, phNewContext, pOutput, pfContextAttr, ptsExpiry)#uselib "SECUR32.dll"
#func global SaslInitializeSecurityContextA "SaslInitializeSecurityContextA" sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr
; SaslInitializeSecurityContextA varptr(phCredential), varptr(phContext), pszTargetName, fContextReq, Reserved1, TargetDataRep, varptr(pInput), Reserved2, varptr(phNewContext), varptr(pOutput), varptr(pfContextAttr), varptr(ptsExpiry) ; 戻り値は stat
; phCredential : SecHandle* optional -> "sptr"
; phContext : SecHandle* optional -> "sptr"
; pszTargetName : LPSTR optional -> "sptr"
; fContextReq : ISC_REQ_FLAGS -> "sptr"
; Reserved1 : DWORD -> "sptr"
; TargetDataRep : DWORD -> "sptr"
; pInput : SecBufferDesc* optional -> "sptr"
; Reserved2 : DWORD -> "sptr"
; phNewContext : SecHandle* optional, in/out -> "sptr"
; pOutput : SecBufferDesc* optional, in/out -> "sptr"
; pfContextAttr : DWORD* out -> "sptr"
; ptsExpiry : LONGLONG* optional, out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "SECUR32.dll" #cfunc global SaslInitializeSecurityContextA "SaslInitializeSecurityContextA" var, var, str, int, int, int, var, int, var, var, var, var ; res = SaslInitializeSecurityContextA(phCredential, phContext, pszTargetName, fContextReq, Reserved1, TargetDataRep, pInput, Reserved2, phNewContext, pOutput, pfContextAttr, ptsExpiry) ; phCredential : SecHandle* optional -> "var" ; phContext : SecHandle* optional -> "var" ; pszTargetName : LPSTR optional -> "str" ; 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 SaslInitializeSecurityContextA "SaslInitializeSecurityContextA" sptr, sptr, str, int, int, int, sptr, int, sptr, sptr, sptr, sptr ; res = SaslInitializeSecurityContextA(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 : LPSTR optional -> "str" ; 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 SaslInitializeSecurityContextA(SecHandle* phCredential, SecHandle* phContext, LPSTR 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 SaslInitializeSecurityContextA "SaslInitializeSecurityContextA" var, var, str, int, int, int, var, int, var, var, var, var ; res = SaslInitializeSecurityContextA(phCredential, phContext, pszTargetName, fContextReq, Reserved1, TargetDataRep, pInput, Reserved2, phNewContext, pOutput, pfContextAttr, ptsExpiry) ; phCredential : SecHandle* optional -> "var" ; phContext : SecHandle* optional -> "var" ; pszTargetName : LPSTR optional -> "str" ; 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 SaslInitializeSecurityContextA(SecHandle* phCredential, SecHandle* phContext, LPSTR 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 SaslInitializeSecurityContextA "SaslInitializeSecurityContextA" intptr, intptr, str, int, int, int, intptr, int, intptr, intptr, intptr, intptr ; res = SaslInitializeSecurityContextA(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 : LPSTR optional -> "str" ; 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")
procSaslInitializeSecurityContextA = secur32.NewProc("SaslInitializeSecurityContextA")
)
// phCredential (SecHandle* optional), phContext (SecHandle* optional), pszTargetName (LPSTR 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 := procSaslInitializeSecurityContextA.Call(
uintptr(phCredential),
uintptr(phContext),
uintptr(unsafe.Pointer(windows.BytePtrFromString(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 SaslInitializeSecurityContextA(
phCredential: Pointer; // SecHandle* optional
phContext: Pointer; // SecHandle* optional
pszTargetName: PAnsiChar; // LPSTR 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 'SaslInitializeSecurityContextA';result := DllCall("SECUR32\SaslInitializeSecurityContextA"
, "Ptr", phCredential ; SecHandle* optional
, "Ptr", phContext ; SecHandle* optional
, "AStr", pszTargetName ; LPSTR 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●SaslInitializeSecurityContextA(phCredential, phContext, pszTargetName, fContextReq, Reserved1, TargetDataRep, pInput, Reserved2, phNewContext, pOutput, pfContextAttr, ptsExpiry) = DLL("SECUR32.dll", "int SaslInitializeSecurityContextA(void*, void*, char*, dword, dword, dword, void*, dword, void*, void*, void*, void*)")
# 呼び出し: SaslInitializeSecurityContextA(phCredential, phContext, pszTargetName, fContextReq, Reserved1, TargetDataRep, pInput, Reserved2, phNewContext, pOutput, pfContextAttr, ptsExpiry)
# phCredential : SecHandle* optional -> "void*"
# phContext : SecHandle* optional -> "void*"
# pszTargetName : LPSTR 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)。const std = @import("std");
extern "secur32" fn SaslInitializeSecurityContextA(
phCredential: [*c]SecHandle, // SecHandle* optional
phContext: [*c]SecHandle, // SecHandle* optional
pszTargetName: [*c]const u8, // LPSTR 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;proc SaslInitializeSecurityContextA(
phCredential: ptr SecHandle, # SecHandle* optional
phContext: ptr SecHandle, # SecHandle* optional
pszTargetName: cstring, # LPSTR 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: "SaslInitializeSecurityContextA", stdcall, dynlib: "SECUR32.dll".}pragma(lib, "secur32");
extern(Windows)
int SaslInitializeSecurityContextA(
SecHandle* phCredential, // SecHandle* optional
SecHandle* phContext, // SecHandle* optional
const(char)* pszTargetName, // LPSTR 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((:SaslInitializeSecurityContextA, "SECUR32.dll"), stdcall, Int32,
(Ptr{SecHandle}, Ptr{SecHandle}, Cstring, 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 : LPSTR optional -> Cstring
# 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 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t SaslInitializeSecurityContextA(
void* phCredential,
void* phContext,
const char* 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.SaslInitializeSecurityContextA(phCredential, phContext, pszTargetName, fContextReq, Reserved1, TargetDataRep, pInput, Reserved2, phNewContext, pOutput, pfContextAttr, ptsExpiry)
-- phCredential : SecHandle* optional
-- phContext : SecHandle* optional
-- pszTargetName : LPSTR 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 に追加すること。const koffi = require('koffi');
const lib = koffi.load('SECUR32.dll');
const SaslInitializeSecurityContextA = lib.func('__stdcall', 'SaslInitializeSecurityContextA', 'int32_t', ['void *', 'void *', 'str', 'uint32_t', 'uint32_t', 'uint32_t', 'void *', 'uint32_t', 'void *', 'void *', 'uint32_t *', 'int64_t *']);
// SaslInitializeSecurityContextA(phCredential, phContext, pszTargetName, fContextReq, Reserved1, TargetDataRep, pInput, Reserved2, phNewContext, pOutput, pfContextAttr, ptsExpiry)
// phCredential : SecHandle* optional -> 'void *'
// phContext : SecHandle* optional -> 'void *'
// pszTargetName : LPSTR optional -> 'str'
// 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", {
SaslInitializeSecurityContextA: { parameters: ["pointer", "pointer", "buffer", "u32", "u32", "u32", "pointer", "u32", "pointer", "pointer", "pointer", "pointer"], result: "i32" },
});
// lib.symbols.SaslInitializeSecurityContextA(phCredential, phContext, pszTargetName, fContextReq, Reserved1, TargetDataRep, pInput, Reserved2, phNewContext, pOutput, pfContextAttr, ptsExpiry)
// phCredential : SecHandle* optional -> "pointer"
// phContext : SecHandle* optional -> "pointer"
// pszTargetName : LPSTR 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"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t SaslInitializeSecurityContextA(
void* phCredential,
void* phContext,
const char* 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->SaslInitializeSecurityContextA(phCredential, phContext, pszTargetName, fContextReq, Reserved1, TargetDataRep, pInput, Reserved2, phNewContext, pOutput, pfContextAttr, ptsExpiry);
// phCredential : SecHandle* optional
// phContext : SecHandle* optional
// pszTargetName : LPSTR 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.ASCII_OPTIONS);
int SaslInitializeSecurityContextA(
Pointer phCredential, // SecHandle* optional
Pointer phContext, // SecHandle* optional
String pszTargetName, // LPSTR 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
);
}@[Link("secur32")]
lib LibSECUR32
fun SaslInitializeSecurityContextA = SaslInitializeSecurityContextA(
phCredential : SecHandle*, # SecHandle* optional
phContext : SecHandle*, # SecHandle* optional
pszTargetName : UInt8*, # LPSTR 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 SaslInitializeSecurityContextANative = Int32 Function(Pointer<Void>, Pointer<Void>, Pointer<Utf8>, Uint32, Uint32, Uint32, Pointer<Void>, Uint32, Pointer<Void>, Pointer<Void>, Pointer<Uint32>, Pointer<Int64>);
typedef SaslInitializeSecurityContextADart = int Function(Pointer<Void>, Pointer<Void>, Pointer<Utf8>, int, int, int, Pointer<Void>, int, Pointer<Void>, Pointer<Void>, Pointer<Uint32>, Pointer<Int64>);
final SaslInitializeSecurityContextA = DynamicLibrary.open('SECUR32.dll')
.lookupFunction<SaslInitializeSecurityContextANative, SaslInitializeSecurityContextADart>('SaslInitializeSecurityContextA');
// phCredential : SecHandle* optional -> Pointer<Void>
// phContext : SecHandle* optional -> Pointer<Void>
// pszTargetName : LPSTR optional -> Pointer<Utf8>
// 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 SaslInitializeSecurityContextA(
phCredential: Pointer; // SecHandle* optional
phContext: Pointer; // SecHandle* optional
pszTargetName: PAnsiChar; // LPSTR 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 'SaslInitializeSecurityContextA';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "SaslInitializeSecurityContextA"
c_SaslInitializeSecurityContextA :: Ptr () -> Ptr () -> CString -> Word32 -> Word32 -> Word32 -> Ptr () -> Word32 -> Ptr () -> Ptr () -> Ptr Word32 -> Ptr Int64 -> IO Int32
-- phCredential : SecHandle* optional -> Ptr ()
-- phContext : SecHandle* optional -> Ptr ()
-- pszTargetName : LPSTR optional -> CString
-- 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 saslinitializesecuritycontexta =
foreign "SaslInitializeSecurityContextA"
((ptr void) @-> (ptr void) @-> string @-> 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 : LPSTR optional -> string *)
(* 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 ("SaslInitializeSecurityContextA" sasl-initialize-security-context-a :convention :stdcall) :int32
(ph-credential :pointer) ; SecHandle* optional
(ph-context :pointer) ; SecHandle* optional
(psz-target-name :string) ; LPSTR 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 $SaslInitializeSecurityContextA = Win32::API::More->new('SECUR32',
'int SaslInitializeSecurityContextA(LPVOID phCredential, LPVOID phContext, LPCSTR pszTargetName, DWORD fContextReq, DWORD Reserved1, DWORD TargetDataRep, LPVOID pInput, DWORD Reserved2, LPVOID phNewContext, LPVOID pOutput, LPVOID pfContextAttr, LPVOID ptsExpiry)');
# my $ret = $SaslInitializeSecurityContextA->Call($phCredential, $phContext, $pszTargetName, $fContextReq, $Reserved1, $TargetDataRep, $pInput, $Reserved2, $phNewContext, $pOutput, $pfContextAttr, $ptsExpiry);
# phCredential : SecHandle* optional -> LPVOID
# phContext : SecHandle* optional -> LPVOID
# pszTargetName : LPSTR optional -> LPCSTR
# 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 を使用。関連項目
文字セット違い
- f SaslInitializeSecurityContextW (Unicode版) — SASL用クライアント側セキュリティコンテキストを初期化する(Unicode版)。