AcceptSecurityContext
関数シグネチャ
// SECUR32.dll
#include <windows.h>
HRESULT AcceptSecurityContext(
SecHandle* phCredential, // optional
SecHandle* phContext, // optional
SecBufferDesc* pInput, // optional
ASC_REQ_FLAGS fContextReq,
DWORD TargetDataRep,
SecHandle* phNewContext, // optional
SecBufferDesc* pOutput, // optional
DWORD* pfContextAttr,
LONGLONG* ptsExpiry // optional
);パラメーター
| 名前 | 型 | 方向 | 説明 | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| phCredential | SecHandle* | inoptional | サーバー資格情報へのハンドル。このハンドルを取得するには、サーバーは SECPKG_CRED_INBOUND または SECPKG_CRED_BOTH フラグのいずれかを設定して AcquireCredentialsHandle (CredSSP) 関数を呼び出します。 | ||||||||||||||||
| phContext | SecHandle* | inoptional | CtxtHandle 構造体へのポインター。AcceptSecurityContext (CredSSP) の最初の呼び出しでは、このポインターは NULL です。以降の呼び出しでは、phContext に、最初の呼び出しで phNewContext パラメーターに返された部分的に形成されたコンテキストを指定します。 | ||||||||||||||||
| pInput | SecBufferDesc* | inoptional | クライアントによる InitializeSecurityContext (CredSSP) の呼び出しで生成された SecBufferDesc 構造体へのポインター。この構造体には入力バッファー記述子が含まれます。 最初のバッファーは SECBUFFER_TOKEN 型で、クライアントから受信したセキュリティ トークンを含んでいる必要があります。2 番目のバッファーは SECBUFFER_EMPTY 型である必要があります。 | ||||||||||||||||
| fContextReq | ASC_REQ_FLAGS | in | -コンテキストを確立するためにサーバーが必要とする属性を指定するビット フラグ。ビット フラグはビットごとの OR 演算で組み合わせることができます。このパラメーターには、次の値の 1 つ以上を指定できます。
使用可能な属性フラグとその意味については、 コンテキスト要件を参照してください。このパラメーターに使用するフラグには ASC_REQ というプレフィックスが付きます (例: ASC_REQ_DELEGATE)。 要求した属性がクライアントでサポートされない場合があります。詳細については、pfContextAttr パラメーターを参照してください。 | ||||||||||||||||
| TargetDataRep | DWORD | in | ターゲットにおけるバイト順序などのデータ表現。このパラメーターには SECURITY_NATIVE_DREP または SECURITY_NETWORK_DREP のいずれかを指定できます。 | ||||||||||||||||
| phNewContext | SecHandle* | inoutoptional | CtxtHandle 構造体へのポインター。AcceptSecurityContext (CredSSP) の最初の呼び出しでは、このポインターが新しいコンテキスト ハンドルを受け取ります。以降の呼び出しでは、phNewContext は phContext パラメーターで指定したハンドルと同じでもかまいません。 | ||||||||||||||||
| pOutput | SecBufferDesc* | inoutoptional | 出力バッファー記述子を含む SecBufferDesc 構造体へのポインター。このバッファーは、InitializeSecurityContext (CredSSP) の追加の呼び出しへの入力として使用されるよう、クライアントに送信されます。関数が SEC_E_OK を返した場合でも、出力バッファーが生成されることがあります。生成されたバッファーはすべてクライアント アプリケーションに送り返す必要があります。 出力時に、このバッファーはセキュリティ コンテキストのトークンを受け取ります。このトークンはクライアントに送信する必要があります。この関数は SECBUFFER_EXTRA 型のバッファーを返すこともあります。 | ||||||||||||||||
| pfContextAttr | DWORD* | out | 確立されたコンテキストの属性を示すビット フラグのセットへのポインター。各種属性の説明については、 コンテキスト要件を参照してください。このパラメーターに使用するフラグには ASC_RET というプレフィックスが付きます (例: ASC_RET_DELEGATE)。 最後の関数呼び出しが正常に返るまでは、セキュリティ関連の属性を確認しないでください。ASC_RET_ALLOCATED_MEMORY フラグのようなセキュリティに関係しない属性フラグは、最後の戻りの前に確認できます。 | ||||||||||||||||
| ptsExpiry | LONGLONG* | outoptional | コンテキストの有効期限を受け取る TimeStamp 構造体へのポインター。セキュリティ パッケージは常にこの値をローカル時刻で返すことをお勧めします。 注 認証プロセスの最後の呼び出しまでは、ネゴシエーションの後の段階でさらに情報が提供されるため、コンテキストの有効期限が正しくない場合があります。したがって、関数の最後の呼び出しまで ptsTimeStamp は NULL にする必要があります。
|
戻り値の型: HRESULT
公式ドキュメント
トランスポート アプリケーションのサーバー コンポーネントが、サーバーとリモート クライアントの間でセキュリティ コンテキストを確立できるようにします。
戻り値
この関数は次のいずれかの値を返します。
| リターン コード/値 | 説明 |
|---|---|
|
関数は成功しました。入力バッファーのデータが不完全です。アプリケーションはクライアントから追加のデータを読み取り、AcceptSecurityContext (CredSSP) を再度呼び出す必要があります。 |
|
関数は失敗しました。要求された操作を完了するのに十分なメモリがありません。 |
|
関数は失敗しました。SSPI エラー コードに対応付けられないエラーが発生しました。 |
|
関数は失敗しました。関数に渡されたハンドルが無効です。 |
|
関数は失敗しました。関数に渡されたトークンが無効です。 |
|
ログオンに失敗しました。 |
|
関数は失敗しました。認証のために接続できる機関がありませんでした。原因として次の状況が考えられます。
|
|
関数は失敗しました。phCredential パラメーターで指定された資格情報ハンドルが無効です。 |
|
関数は成功しました。クライアントから受信したセキュリティ コンテキストが受け入れられました。関数が出力トークンを生成した場合、そのトークンをクライアント プロセスに送信する必要があります。 |
|
関数は失敗しました。fContextReq パラメーターに無効なコンテキスト属性フラグ (ASC_REQ_DELEGATE または ASC_REQ_PROMPT_FOR_CREDS) が指定されました。 |
|
関数は成功しました。サーバーは CompleteAuthToken を呼び出し、出力トークンをクライアントに渡す必要があります。その後、サーバーは AcceptSecurityContext (CredSSP) をもう一度呼び出す前に、クライアントからの返答トークンを待つ必要があります。 |
|
関数は成功しました。サーバーは CompleteAuthToken を呼び出す前に、クライアントからのメッセージの構築を完了する必要があります。 |
|
関数は成功しました。サーバーは出力トークンをクライアントに送信し、返されるトークンを待つ必要があります。返されたトークンは、AcceptSecurityContext (CredSSP) の次の呼び出しで pInput に渡します。 |
解説(Remarks)
AcceptSecurityContext (CredSSP) 関数は、 InitializeSecurityContext (CredSSP) 関数に対応するサーバー側の関数です。
サーバーはクライアントから要求を受け取ると、fContextReq パラメーターを使用してセッションに要求する内容を指定します。このようにして、サーバーは機密性のあるセッションや整合性チェック付きのセッションを使用できることをクライアントに要求でき、その要求を満たせないクライアントを拒否できます。あるいは、サーバーは何も要求しないこともできます。その場合、クライアントが要求するか提供できるものが pfContextAttr パラメーターに返されます。
fContextReq パラメーターと pfContextAttr パラメーターは、さまざまなコンテキスト属性を表すビットマスクです。各種属性の説明については、 コンテキスト要件を参照してください。
セキュリティ コンテキストが確立された後、サーバー アプリケーションは QuerySecurityContextToken 関数を使用して、クライアント証明書がマップされたユーザー アカウントへのハンドルを取得できます。また、サーバーは ImpersonateSecurityContext 関数を使用してユーザーを偽装できます。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// SECUR32.dll
#include <windows.h>
HRESULT AcceptSecurityContext(
SecHandle* phCredential, // optional
SecHandle* phContext, // optional
SecBufferDesc* pInput, // optional
ASC_REQ_FLAGS fContextReq,
DWORD TargetDataRep,
SecHandle* phNewContext, // optional
SecBufferDesc* pOutput, // optional
DWORD* pfContextAttr,
LONGLONG* ptsExpiry // optional
);[DllImport("SECUR32.dll", ExactSpelling = true)]
static extern int AcceptSecurityContext(
IntPtr phCredential, // SecHandle* optional
IntPtr phContext, // SecHandle* optional
IntPtr pInput, // SecBufferDesc* optional
uint fContextReq, // ASC_REQ_FLAGS
uint TargetDataRep, // 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", ExactSpelling:=True)>
Public Shared Function AcceptSecurityContext(
phCredential As IntPtr, ' SecHandle* optional
phContext As IntPtr, ' SecHandle* optional
pInput As IntPtr, ' SecBufferDesc* optional
fContextReq As UInteger, ' ASC_REQ_FLAGS
TargetDataRep 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
' pInput : SecBufferDesc* optional
' fContextReq : ASC_REQ_FLAGS
' TargetDataRep : DWORD
' phNewContext : SecHandle* optional, in/out
' pOutput : SecBufferDesc* optional, in/out
' pfContextAttr : DWORD* out
' ptsExpiry : LONGLONG* optional, out
Declare PtrSafe Function AcceptSecurityContext Lib "secur32" ( _
ByVal phCredential As LongPtr, _
ByVal phContext As LongPtr, _
ByVal pInput As LongPtr, _
ByVal fContextReq As Long, _
ByVal TargetDataRep 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
AcceptSecurityContext = ctypes.windll.secur32.AcceptSecurityContext
AcceptSecurityContext.restype = ctypes.c_int
AcceptSecurityContext.argtypes = [
ctypes.c_void_p, # phCredential : SecHandle* optional
ctypes.c_void_p, # phContext : SecHandle* optional
ctypes.c_void_p, # pInput : SecBufferDesc* optional
wintypes.DWORD, # fContextReq : ASC_REQ_FLAGS
wintypes.DWORD, # TargetDataRep : 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')
AcceptSecurityContext = Fiddle::Function.new(
lib['AcceptSecurityContext'],
[
Fiddle::TYPE_VOIDP, # phCredential : SecHandle* optional
Fiddle::TYPE_VOIDP, # phContext : SecHandle* optional
Fiddle::TYPE_VOIDP, # pInput : SecBufferDesc* optional
-Fiddle::TYPE_INT, # fContextReq : ASC_REQ_FLAGS
-Fiddle::TYPE_INT, # TargetDataRep : 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 AcceptSecurityContext(
phCredential: *mut SecHandle, // SecHandle* optional
phContext: *mut SecHandle, // SecHandle* optional
pInput: *mut SecBufferDesc, // SecBufferDesc* optional
fContextReq: u32, // ASC_REQ_FLAGS
TargetDataRep: 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")]
public static extern int AcceptSecurityContext(IntPtr phCredential, IntPtr phContext, IntPtr pInput, uint fContextReq, uint TargetDataRep, IntPtr phNewContext, IntPtr pOutput, out uint pfContextAttr, IntPtr ptsExpiry);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SECUR32_AcceptSecurityContext' -Namespace Win32 -PassThru
# $api::AcceptSecurityContext(phCredential, phContext, pInput, fContextReq, TargetDataRep, phNewContext, pOutput, pfContextAttr, ptsExpiry)#uselib "SECUR32.dll"
#func global AcceptSecurityContext "AcceptSecurityContext" sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr
; AcceptSecurityContext varptr(phCredential), varptr(phContext), varptr(pInput), fContextReq, TargetDataRep, varptr(phNewContext), varptr(pOutput), varptr(pfContextAttr), varptr(ptsExpiry) ; 戻り値は stat
; phCredential : SecHandle* optional -> "sptr"
; phContext : SecHandle* optional -> "sptr"
; pInput : SecBufferDesc* optional -> "sptr"
; fContextReq : ASC_REQ_FLAGS -> "sptr"
; TargetDataRep : 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 AcceptSecurityContext "AcceptSecurityContext" var, var, var, int, int, var, var, var, var ; res = AcceptSecurityContext(phCredential, phContext, pInput, fContextReq, TargetDataRep, phNewContext, pOutput, pfContextAttr, ptsExpiry) ; phCredential : SecHandle* optional -> "var" ; phContext : SecHandle* optional -> "var" ; pInput : SecBufferDesc* optional -> "var" ; fContextReq : ASC_REQ_FLAGS -> "int" ; TargetDataRep : 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 AcceptSecurityContext "AcceptSecurityContext" sptr, sptr, sptr, int, int, sptr, sptr, sptr, sptr ; res = AcceptSecurityContext(varptr(phCredential), varptr(phContext), varptr(pInput), fContextReq, TargetDataRep, varptr(phNewContext), varptr(pOutput), varptr(pfContextAttr), varptr(ptsExpiry)) ; phCredential : SecHandle* optional -> "sptr" ; phContext : SecHandle* optional -> "sptr" ; pInput : SecBufferDesc* optional -> "sptr" ; fContextReq : ASC_REQ_FLAGS -> "int" ; TargetDataRep : 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 AcceptSecurityContext(SecHandle* phCredential, SecHandle* phContext, SecBufferDesc* pInput, ASC_REQ_FLAGS fContextReq, DWORD TargetDataRep, SecHandle* phNewContext, SecBufferDesc* pOutput, DWORD* pfContextAttr, LONGLONG* ptsExpiry) #uselib "SECUR32.dll" #cfunc global AcceptSecurityContext "AcceptSecurityContext" var, var, var, int, int, var, var, var, var ; res = AcceptSecurityContext(phCredential, phContext, pInput, fContextReq, TargetDataRep, phNewContext, pOutput, pfContextAttr, ptsExpiry) ; phCredential : SecHandle* optional -> "var" ; phContext : SecHandle* optional -> "var" ; pInput : SecBufferDesc* optional -> "var" ; fContextReq : ASC_REQ_FLAGS -> "int" ; TargetDataRep : 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 AcceptSecurityContext(SecHandle* phCredential, SecHandle* phContext, SecBufferDesc* pInput, ASC_REQ_FLAGS fContextReq, DWORD TargetDataRep, SecHandle* phNewContext, SecBufferDesc* pOutput, DWORD* pfContextAttr, LONGLONG* ptsExpiry) #uselib "SECUR32.dll" #cfunc global AcceptSecurityContext "AcceptSecurityContext" intptr, intptr, intptr, int, int, intptr, intptr, intptr, intptr ; res = AcceptSecurityContext(varptr(phCredential), varptr(phContext), varptr(pInput), fContextReq, TargetDataRep, varptr(phNewContext), varptr(pOutput), varptr(pfContextAttr), varptr(ptsExpiry)) ; phCredential : SecHandle* optional -> "intptr" ; phContext : SecHandle* optional -> "intptr" ; pInput : SecBufferDesc* optional -> "intptr" ; fContextReq : ASC_REQ_FLAGS -> "int" ; TargetDataRep : 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")
procAcceptSecurityContext = secur32.NewProc("AcceptSecurityContext")
)
// phCredential (SecHandle* optional), phContext (SecHandle* optional), pInput (SecBufferDesc* optional), fContextReq (ASC_REQ_FLAGS), TargetDataRep (DWORD), phNewContext (SecHandle* optional, in/out), pOutput (SecBufferDesc* optional, in/out), pfContextAttr (DWORD* out), ptsExpiry (LONGLONG* optional, out)
r1, _, err := procAcceptSecurityContext.Call(
uintptr(phCredential),
uintptr(phContext),
uintptr(pInput),
uintptr(fContextReq),
uintptr(TargetDataRep),
uintptr(phNewContext),
uintptr(pOutput),
uintptr(pfContextAttr),
uintptr(ptsExpiry),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // HRESULTfunction AcceptSecurityContext(
phCredential: Pointer; // SecHandle* optional
phContext: Pointer; // SecHandle* optional
pInput: Pointer; // SecBufferDesc* optional
fContextReq: DWORD; // ASC_REQ_FLAGS
TargetDataRep: 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 'AcceptSecurityContext';result := DllCall("SECUR32\AcceptSecurityContext"
, "Ptr", phCredential ; SecHandle* optional
, "Ptr", phContext ; SecHandle* optional
, "Ptr", pInput ; SecBufferDesc* optional
, "UInt", fContextReq ; ASC_REQ_FLAGS
, "UInt", TargetDataRep ; 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●AcceptSecurityContext(phCredential, phContext, pInput, fContextReq, TargetDataRep, phNewContext, pOutput, pfContextAttr, ptsExpiry) = DLL("SECUR32.dll", "int AcceptSecurityContext(void*, void*, void*, dword, dword, void*, void*, void*, void*)")
# 呼び出し: AcceptSecurityContext(phCredential, phContext, pInput, fContextReq, TargetDataRep, phNewContext, pOutput, pfContextAttr, ptsExpiry)
# phCredential : SecHandle* optional -> "void*"
# phContext : SecHandle* optional -> "void*"
# pInput : SecBufferDesc* optional -> "void*"
# fContextReq : ASC_REQ_FLAGS -> "dword"
# TargetDataRep : 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 AcceptSecurityContext(
phCredential: [*c]SecHandle, // SecHandle* optional
phContext: [*c]SecHandle, // SecHandle* optional
pInput: [*c]SecBufferDesc, // SecBufferDesc* optional
fContextReq: u32, // ASC_REQ_FLAGS
TargetDataRep: 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 AcceptSecurityContext(
phCredential: ptr SecHandle, # SecHandle* optional
phContext: ptr SecHandle, # SecHandle* optional
pInput: ptr SecBufferDesc, # SecBufferDesc* optional
fContextReq: uint32, # ASC_REQ_FLAGS
TargetDataRep: 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: "AcceptSecurityContext", stdcall, dynlib: "SECUR32.dll".}pragma(lib, "secur32");
extern(Windows)
int AcceptSecurityContext(
SecHandle* phCredential, // SecHandle* optional
SecHandle* phContext, // SecHandle* optional
SecBufferDesc* pInput, // SecBufferDesc* optional
uint fContextReq, // ASC_REQ_FLAGS
uint TargetDataRep, // DWORD
SecHandle* phNewContext, // SecHandle* optional, in/out
SecBufferDesc* pOutput, // SecBufferDesc* optional, in/out
uint* pfContextAttr, // DWORD* out
long* ptsExpiry // LONGLONG* optional, out
);ccall((:AcceptSecurityContext, "SECUR32.dll"), stdcall, Int32,
(Ptr{SecHandle}, Ptr{SecHandle}, Ptr{SecBufferDesc}, UInt32, UInt32, Ptr{SecHandle}, Ptr{SecBufferDesc}, Ptr{UInt32}, Ptr{Int64}),
phCredential, phContext, pInput, fContextReq, TargetDataRep, phNewContext, pOutput, pfContextAttr, ptsExpiry)
# phCredential : SecHandle* optional -> Ptr{SecHandle}
# phContext : SecHandle* optional -> Ptr{SecHandle}
# pInput : SecBufferDesc* optional -> Ptr{SecBufferDesc}
# fContextReq : ASC_REQ_FLAGS -> UInt32
# TargetDataRep : 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 AcceptSecurityContext(
void* phCredential,
void* phContext,
void* pInput,
uint32_t fContextReq,
uint32_t TargetDataRep,
void* phNewContext,
void* pOutput,
uint32_t* pfContextAttr,
int64_t* ptsExpiry);
]]
local secur32 = ffi.load("secur32")
-- secur32.AcceptSecurityContext(phCredential, phContext, pInput, fContextReq, TargetDataRep, phNewContext, pOutput, pfContextAttr, ptsExpiry)
-- phCredential : SecHandle* optional
-- phContext : SecHandle* optional
-- pInput : SecBufferDesc* optional
-- fContextReq : ASC_REQ_FLAGS
-- TargetDataRep : 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 AcceptSecurityContext = lib.func('__stdcall', 'AcceptSecurityContext', 'int32_t', ['void *', 'void *', 'void *', 'uint32_t', 'uint32_t', 'void *', 'void *', 'uint32_t *', 'int64_t *']);
// AcceptSecurityContext(phCredential, phContext, pInput, fContextReq, TargetDataRep, phNewContext, pOutput, pfContextAttr, ptsExpiry)
// phCredential : SecHandle* optional -> 'void *'
// phContext : SecHandle* optional -> 'void *'
// pInput : SecBufferDesc* optional -> 'void *'
// fContextReq : ASC_REQ_FLAGS -> 'uint32_t'
// TargetDataRep : 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", {
AcceptSecurityContext: { parameters: ["pointer", "pointer", "pointer", "u32", "u32", "pointer", "pointer", "pointer", "pointer"], result: "i32" },
});
// lib.symbols.AcceptSecurityContext(phCredential, phContext, pInput, fContextReq, TargetDataRep, phNewContext, pOutput, pfContextAttr, ptsExpiry)
// phCredential : SecHandle* optional -> "pointer"
// phContext : SecHandle* optional -> "pointer"
// pInput : SecBufferDesc* optional -> "pointer"
// fContextReq : ASC_REQ_FLAGS -> "u32"
// TargetDataRep : DWORD -> "u32"
// phNewContext : SecHandle* optional, in/out -> "pointer"
// pOutput : SecBufferDesc* optional, in/out -> "pointer"
// pfContextAttr : DWORD* out -> "pointer"
// ptsExpiry : LONGLONG* optional, out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t AcceptSecurityContext(
void* phCredential,
void* phContext,
void* pInput,
uint32_t fContextReq,
uint32_t TargetDataRep,
void* phNewContext,
void* pOutput,
uint32_t* pfContextAttr,
int64_t* ptsExpiry);
C, "SECUR32.dll");
// $ffi->AcceptSecurityContext(phCredential, phContext, pInput, fContextReq, TargetDataRep, phNewContext, pOutput, pfContextAttr, ptsExpiry);
// phCredential : SecHandle* optional
// phContext : SecHandle* optional
// pInput : SecBufferDesc* optional
// fContextReq : ASC_REQ_FLAGS
// TargetDataRep : 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);
int AcceptSecurityContext(
Pointer phCredential, // SecHandle* optional
Pointer phContext, // SecHandle* optional
Pointer pInput, // SecBufferDesc* optional
int fContextReq, // ASC_REQ_FLAGS
int TargetDataRep, // 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 AcceptSecurityContext = AcceptSecurityContext(
phCredential : SecHandle*, # SecHandle* optional
phContext : SecHandle*, # SecHandle* optional
pInput : SecBufferDesc*, # SecBufferDesc* optional
fContextReq : UInt32, # ASC_REQ_FLAGS
TargetDataRep : 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 AcceptSecurityContextNative = Int32 Function(Pointer<Void>, Pointer<Void>, Pointer<Void>, Uint32, Uint32, Pointer<Void>, Pointer<Void>, Pointer<Uint32>, Pointer<Int64>);
typedef AcceptSecurityContextDart = int Function(Pointer<Void>, Pointer<Void>, Pointer<Void>, int, int, Pointer<Void>, Pointer<Void>, Pointer<Uint32>, Pointer<Int64>);
final AcceptSecurityContext = DynamicLibrary.open('SECUR32.dll')
.lookupFunction<AcceptSecurityContextNative, AcceptSecurityContextDart>('AcceptSecurityContext');
// phCredential : SecHandle* optional -> Pointer<Void>
// phContext : SecHandle* optional -> Pointer<Void>
// pInput : SecBufferDesc* optional -> Pointer<Void>
// fContextReq : ASC_REQ_FLAGS -> Uint32
// TargetDataRep : 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 AcceptSecurityContext(
phCredential: Pointer; // SecHandle* optional
phContext: Pointer; // SecHandle* optional
pInput: Pointer; // SecBufferDesc* optional
fContextReq: DWORD; // ASC_REQ_FLAGS
TargetDataRep: 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 'AcceptSecurityContext';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "AcceptSecurityContext"
c_AcceptSecurityContext :: Ptr () -> Ptr () -> Ptr () -> Word32 -> Word32 -> Ptr () -> Ptr () -> Ptr Word32 -> Ptr Int64 -> IO Int32
-- phCredential : SecHandle* optional -> Ptr ()
-- phContext : SecHandle* optional -> Ptr ()
-- pInput : SecBufferDesc* optional -> Ptr ()
-- fContextReq : ASC_REQ_FLAGS -> Word32
-- TargetDataRep : 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 acceptsecuritycontext =
foreign "AcceptSecurityContext"
((ptr void) @-> (ptr void) @-> (ptr void) @-> uint32_t @-> 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) *)
(* pInput : SecBufferDesc* optional -> (ptr void) *)
(* fContextReq : ASC_REQ_FLAGS -> uint32_t *)
(* TargetDataRep : 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 ("AcceptSecurityContext" accept-security-context :convention :stdcall) :int32
(ph-credential :pointer) ; SecHandle* optional
(ph-context :pointer) ; SecHandle* optional
(p-input :pointer) ; SecBufferDesc* optional
(f-context-req :uint32) ; ASC_REQ_FLAGS
(target-data-rep :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 $AcceptSecurityContext = Win32::API::More->new('SECUR32',
'int AcceptSecurityContext(LPVOID phCredential, LPVOID phContext, LPVOID pInput, DWORD fContextReq, DWORD TargetDataRep, LPVOID phNewContext, LPVOID pOutput, LPVOID pfContextAttr, LPVOID ptsExpiry)');
# my $ret = $AcceptSecurityContext->Call($phCredential, $phContext, $pInput, $fContextReq, $TargetDataRep, $phNewContext, $pOutput, $pfContextAttr, $ptsExpiry);
# phCredential : SecHandle* optional -> LPVOID
# phContext : SecHandle* optional -> LPVOID
# pInput : SecBufferDesc* optional -> LPVOID
# fContextReq : ASC_REQ_FLAGS -> DWORD
# TargetDataRep : 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 DeleteSecurityContext — セキュリティコンテキストを破棄し関連リソースを解放する。
- f InitializeSecurityContextW — クライアント側のセキュリティコンテキストを初期化する(Unicode版)。