How to specify PeerTokenAccessMask in WSAQuerySocketSecurity?

beachbear 1 Reputation point
2020-09-14T20:44:28.233+00:00

The PeerTokenAccessMask field is a ULONG in SOCKET_SECURITY_QUERY_TEMPLATE.
I need to set it to some value to get PeerApplicationAccessTokenHandle and/or PeerMachineAccessTokenHandle.
However I cannot find anywhere how that mask field can be set.
There is no constant definitions anywhere and specifying anything except zero gives me error 10022 (invalid argument) from WSAQuerySocketSecurity().
How can I set that PeerTokenAccessMask correctly to be able to get the token handles?

Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,611 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Rita Han - MSFT 2,161 Reputation points
    2020-09-15T01:56:54.353+00:00

    Hello @beachbear ,

    For access mask for token you can refer to "Access Rights for Access-Token Objects" for a complete list.

    Thank you!


    If the answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


  2. beachbear 1 Reputation point
    2020-09-30T04:27:01.023+00:00

    I was trying to use Secure Socket Extensions to perform integrated Windows authentication on sockets, which was expected to be easier than using SSPI. A client winsock2 application running as some user on computer A connects to a server running on computer B (listening on an overlapped sockets using an I/O completion port). The server must get the user token securely and figure out if the user belongs to certain local user group to allow or disallow the request execution. No encryption is necessary, authentication/authorization is sufficient. Since I could not find how to implement that with Secure Socket Extensions, I had to implement it using SSPI, so technically I solved the problem. However it would be great if Microsoft provided a sample or a more detailed documentation how to achieve the same goal easier and with less code using Secure Socket Extensions. Thank you for your support!


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.