gio: add G_CREDENTIALS_TYPE_WIN32_PID

Credentials are often used to check peer processes details.

With AF_UNIX sockets on Windows, SIO_AF_UNIX_GETPEERPID can
be used to retrive the peer PID.

We will probably introduce more advanced mechanisms later on, though,
but I am not a Windows API expert.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
This commit is contained in:
Marc-André Lureau
2022-01-19 20:35:45 +04:00
parent 568f00d65f
commit 95c3e28af5
5 changed files with 67 additions and 0 deletions

View File

@@ -76,6 +76,10 @@
#include "glibintl.h"
#include "gioprivate.h"
#ifdef G_OS_WIN32
#include "giowin32-afunix.h"
#endif
/**
* SECTION:gsocket
* @short_description: Low-level socket object
@@ -6129,6 +6133,23 @@ g_socket_get_credentials (GSocket *socket,
ucred_free (ucred);
}
}
#elif G_CREDENTIALS_USE_WIN32_PID
{
DWORD peerid, drc;
if (WSAIoctl (socket->priv->fd, SIO_AF_UNIX_GETPEERPID,
NULL, 0U,
&peerid, sizeof(peerid),
/* Windows bug: always 0 https://github.com/microsoft/WSL/issues/4676 */
&drc,
NULL, NULL) == 0)
{
ret = g_credentials_new ();
g_credentials_set_native (ret,
G_CREDENTIALS_TYPE_WIN32_PID,
&peerid);
}
}
#else
#error "G_CREDENTIALS_SOCKET_GET_CREDENTIALS_SUPPORTED is set but this is no code for this platform"
#endif