Skip to content

Latest commit

 

History

History
215 lines (135 loc) · 7.17 KB

nf-ws2tcpip-wsaimpersonatesocketpeer.md

File metadata and controls

215 lines (135 loc) · 7.17 KB
UID title description helpviewer_keywords old-location tech.root ms.assetid ms.date ms.keywords req.header req.include-header req.target-type req.target-min-winverclnt req.target-min-winversvr req.kmdf-ver req.umdf-ver req.ddi-compliance req.unicode-ansi req.idl req.max-support req.namespace req.assembly req.type-library req.lib req.dll req.irql targetos req.typenames req.redist ms.custom f1_keywords dev_langs topic_type api_type api_location api_name
NF:ws2tcpip.WSAImpersonateSocketPeer
WSAImpersonateSocketPeer function (ws2tcpip.h)
Used to impersonate the security principal corresponding to a socket peer in order to perform application-level authorization.
WSAImpersonateSocketPeer
WSAImpersonateSocketPeer function [Winsock]
winsock.wsaimpersonatesocketpeer
ws2tcpip/WSAImpersonateSocketPeer
winsock\wsaimpersonatesocketpeer.htm
WinSock
8dd2c0dd-ca1d-40b8-8e58-a980e67b6941
12/05/2018
WSAImpersonateSocketPeer, WSAImpersonateSocketPeer function [Winsock], winsock.wsaimpersonatesocketpeer, ws2tcpip/WSAImpersonateSocketPeer
ws2tcpip.h
Windows
Windows Vista [desktop apps only]
Windows Server 2008 [desktop apps only]
Fwpuclnt.lib
Fwpuclnt.dll
Windows
19H1
WSAImpersonateSocketPeer
ws2tcpip/WSAImpersonateSocketPeer
c++
APIRef
kbSyntax
DllExport
Fwpuclnt.dll
WSAImpersonateSocketPeer

WSAImpersonateSocketPeer function

-description

The WSAImpersonateSocketPeer function is used to impersonate the security principal corresponding to a socket peer in order to perform application-level authorization.

-parameters

-param Socket [in]

Identifies the application socket.

-param PeerAddr [in, optional]

The IP address of the peer to be impersonated. For connection-oriented sockets, the connected socket uniquely identifies a peer. In this case, this parameter is ignored.

-param PeerAddrLen [in]

The size, in bytes, of the PeerAddress parameter.

-returns

If the function succeeds, the return value is 0. Otherwise, a value of SOCKET_ERROR is returned, and a specific error code can be retrieved by calling WSAGetLastError.

Some possible error codes are listed below.

Error code Meaning
WSAEFAULT
The system detected an invalid address pointer in attempting to use a pointer argument of a call. This error is returned if the PeerAddr parameter was a NULL pointer.
WSAEAFNOSUPPORT
The specified address family is not supported.
WSAEMSGSIZE
A buffer passed was too small.
WSAENOTSOCK
The descriptor passed in the Socket parameter is not a valid socket.

-remarks

The WSAImpersonateSocketPeer function provides an application the ability to impersonate the security principal corresponding to a socket peer in order to perform application-level authorization. If peer user (impersonation) token is available then it will be used for impersonation, otherwise the peer computer token will be used. The WSAImpersonateSocketPeer function can be called only for blocking, non-overlapped sockets. After performing any authorization checks, an application must call the WSARevertImpersonation function to terminate the impersonation.

For connection-oriented sockets, the WSAImpersonateSocketPeer function should be called after a connection is established. For a server application using connection-oriented sockets, the WSAImpersonateSocketPeer should be called after the accept, AcceptEx, or WSAAccept function returns.

For connectionless sockets, the application should call the WSAImpersonateSocketPeer function immediately after the recv, recvfrom, WSARecv, WSARecvEx, WSARecvFrom, or LPFN_WSARECVMSG (WSARecvMsg) function returns for a new peer address.

The WSAImpersonateSocketPeer function can be called multiple times for a single socket.

An error will be returned if the following conditions are not met.

  • The address family of the Socket parameter must be either AF_INET or AF_INET6.
  • The socket type must be either SOCK_STREAM or SOCK_DGRAM.

The WSARevertImpersonation function must be called to end the impersonation.

-see-also

AcceptEx

Using Secure Socket Extensions

WSAAccept

WSADeleteSocketPeerTargetName

WSAQuerySocketSecurity

WSARecv

WSARecvEx

WSARecvFrom

LPFN_WSARECVMSG (WSARecvMsg)

WSARevertImpersonation

WSASetSocketPeerTargetName

WSASetSocketSecurity

Windows Filtering Platform

Windows Filtering Platform API Functions

Winsock Secure Socket Extensions

accept

recv

recvfrom