mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-08-02 07:23:41 +02:00
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:
@@ -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
|
||||
|
Reference in New Issue
Block a user