ホーム › Networking.WinSock › WSARevertImpersonation
WSARevertImpersonation
関数ソケットピアの偽装を解除し元のコンテキストに戻す。
シグネチャ
// fwpuclnt.dll
#include <windows.h>
INT WSARevertImpersonation(void);パラメーターなし。戻り値: INT
公式ドキュメント
ソケットピアの偽装(impersonation)を終了します。これは WSAImpersonateSocketPeer を呼び出し、アクセスチェックを完了した後に呼び出す必要があります。
戻り値
関数が成功した場合、戻り値は 0 です。それ以外の場合は SOCKET_ERROR が返され、特定のエラーコードは WSAGetLastError を呼び出すことで取得できます。
発生し得るエラーコードの一部を以下に示します。
| エラーコード | 意味 |
|---|---|
| 失敗しないはずのシステムコールが失敗しました。 |
解説(Remarks)
WSARevertImpersonation 関数は、呼び出し元のスレッドにソケットピアの偽装を中止させます。スレッドが現在ソケットピアを偽装していない場合は、何も行われません。
WSARevertImpersonation 関数は、WSAImpersonateSocketPeer を呼び出し、すべてのアクセスチェックが完了した後に呼び出す必要があります。
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// fwpuclnt.dll
#include <windows.h>
INT WSARevertImpersonation(void);[DllImport("fwpuclnt.dll", SetLastError = true, ExactSpelling = true)]
static extern int WSARevertImpersonation();<DllImport("fwpuclnt.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function WSARevertImpersonation() As Integer
End FunctionDeclare PtrSafe Function WSARevertImpersonation Lib "fwpuclnt" () As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
WSARevertImpersonation = ctypes.windll.fwpuclnt.WSARevertImpersonation
WSARevertImpersonation.restype = ctypes.c_int
WSARevertImpersonation.argtypes = []
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('fwpuclnt.dll')
WSARevertImpersonation = Fiddle::Function.new(
lib['WSARevertImpersonation'],
[],
Fiddle::TYPE_INT)#[link(name = "fwpuclnt")]
extern "system" {
fn WSARevertImpersonation() -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("fwpuclnt.dll", SetLastError = true)]
public static extern int WSARevertImpersonation();
"@
$api = Add-Type -MemberDefinition $sig -Name 'fwpuclnt_WSARevertImpersonation' -Namespace Win32 -PassThru
# $api::WSARevertImpersonation()#uselib "fwpuclnt.dll"
#func global WSARevertImpersonation "WSARevertImpersonation"
; WSARevertImpersonation ; 戻り値は stat
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "fwpuclnt.dll"
#cfunc global WSARevertImpersonation "WSARevertImpersonation"
; res = WSARevertImpersonation(); INT WSARevertImpersonation()
#uselib "fwpuclnt.dll"
#cfunc global WSARevertImpersonation "WSARevertImpersonation"
; res = WSARevertImpersonation()import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
fwpuclnt = windows.NewLazySystemDLL("fwpuclnt.dll")
procWSARevertImpersonation = fwpuclnt.NewProc("WSARevertImpersonation")
)
r1, _, err := procWSARevertImpersonation.Call()
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // INTfunction WSARevertImpersonation: Integer; stdcall;
external 'fwpuclnt.dll' name 'WSARevertImpersonation';result := DllCall("fwpuclnt\WSARevertImpersonation", "Int")●WSARevertImpersonation() = DLL("fwpuclnt.dll", "int WSARevertImpersonation()")
# 呼び出し: WSARevertImpersonation()
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "fwpuclnt" fn WSARevertImpersonation() callconv(std.os.windows.WINAPI) i32;proc WSARevertImpersonation(): int32 {.importc: "WSARevertImpersonation", stdcall, dynlib: "fwpuclnt.dll".}pragma(lib, "fwpuclnt");
extern(Windows)
int WSARevertImpersonation();ccall((:WSARevertImpersonation, "fwpuclnt.dll"), stdcall, Int32,
(),
)
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t WSARevertImpersonation(void);
]]
local fwpuclnt = ffi.load("fwpuclnt")
-- fwpuclnt.WSARevertImpersonation()
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('fwpuclnt.dll');
const WSARevertImpersonation = lib.func('__stdcall', 'WSARevertImpersonation', 'int32_t', []);
// WSARevertImpersonation()
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("fwpuclnt.dll", {
WSARevertImpersonation: { parameters: [], result: "i32" },
});
// lib.symbols.WSARevertImpersonation()
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t WSARevertImpersonation(void);
C, "fwpuclnt.dll");
// $ffi->WSARevertImpersonation();
// 構造体/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 Fwpuclnt extends StdCallLibrary {
Fwpuclnt INSTANCE = Native.load("fwpuclnt", Fwpuclnt.class);
int WSARevertImpersonation();
}@[Link("fwpuclnt")]
lib Libfwpuclnt
fun WSARevertImpersonation = WSARevertImpersonation() : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef WSARevertImpersonationNative = Int32 Function();
typedef WSARevertImpersonationDart = int Function();
final WSARevertImpersonation = DynamicLibrary.open('fwpuclnt.dll')
.lookupFunction<WSARevertImpersonationNative, WSARevertImpersonationDart>('WSARevertImpersonation');
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function WSARevertImpersonation: Integer; stdcall;
external 'fwpuclnt.dll' name 'WSARevertImpersonation';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "WSARevertImpersonation"
c_WSARevertImpersonation :: IO Int32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let wsarevertimpersonation =
foreign "WSARevertImpersonation"
(void @-> returning int32_t)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library fwpuclnt (t "fwpuclnt.dll"))
(cffi:use-foreign-library fwpuclnt)
(cffi:defcfun ("WSARevertImpersonation" wsarevert-impersonation :convention :stdcall) :int32)
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $WSARevertImpersonation = Win32::API::More->new('fwpuclnt',
'int WSARevertImpersonation()');
# my $ret = $WSARevertImpersonation->Call();
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
公式の関連項目
- f WSADeleteSocketPeerTargetName — ソケットに設定したピアのターゲット名を削除する。
- f WSAImpersonateSocketPeer — ソケットの通信相手のセキュリティコンテキストを偽装する。
- f WSAQuerySocketSecurity — ソケットに適用されたセキュリティ情報を照会する。
- f WSASetSocketPeerTargetName — ソケット通信相手のターゲット名を設定し認証に使用する。
- f WSASetSocketSecurity — ソケットにIPsec等のセキュリティ設定を適用する。