mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-08-02 07:23:41 +02:00
Bug 617483 – Credentials passing
- Make GCredentials instance and class structures private so it can't be subclassed and we don't have to worry about ABI compat issues. This also allows us to get rid of the GCredentialsPrivate struct. - Add a GCredentialsType enumeration that is used whenever exchanging pointers with the user. This allows us to support OSes with multiple native credential types. In particular, it allows supporting OSes where the native credential evolves or even changes over time. - Add g_socket_get_credentials() method. - Add tests for g_socket_get_credentials(). Right now this is in the GDBus peer-to-peer test case but we can change that later. - Move GTcpConnection into a separate gtk-doc page as was already half-done with GUnixConnection. Also finish the GUnixConnection move and ensure send_credentials() and receive_credentials() methods are in the docs. Also nuke comment about GTcpConnection being empty compared to its superclass. Signed-off-by: David Zeuthen <davidz@redhat.com>
This commit is contained in:
@@ -35,6 +35,13 @@
|
||||
#include <gio/gunixsocketaddress.h>
|
||||
#include <gio/gunixfdlist.h>
|
||||
|
||||
/* for struct ucred */
|
||||
#ifdef __linux__
|
||||
#define __USE_GNU
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#endif
|
||||
|
||||
#include "gdbus-tests.h"
|
||||
|
||||
|
||||
@@ -703,6 +710,35 @@ test_peer (void)
|
||||
g_error_free (error);
|
||||
#endif /* G_OS_UNIX */
|
||||
|
||||
/* Check that g_socket_get_credentials() work - this really should
|
||||
* be in a GSocket-specific test suite but no such test suite exists
|
||||
* right now.
|
||||
*/
|
||||
{
|
||||
GSocket *socket;
|
||||
GCredentials *credentials;
|
||||
socket = g_socket_connection_get_socket (G_SOCKET_CONNECTION (g_dbus_connection_get_stream (c)));
|
||||
g_assert (G_IS_SOCKET (socket));
|
||||
error = NULL;
|
||||
credentials = g_socket_get_credentials (socket, &error);
|
||||
#ifdef __linux__
|
||||
{
|
||||
struct ucred *native_creds;
|
||||
g_assert_no_error (error);
|
||||
g_assert (G_IS_CREDENTIALS (credentials));
|
||||
native_creds = g_credentials_get_native (credentials, G_CREDENTIALS_TYPE_LINUX_UCRED);
|
||||
g_assert (native_creds != NULL);
|
||||
g_assert (native_creds->uid == getuid ());
|
||||
g_assert (native_creds->gid == getgid ());
|
||||
g_assert (native_creds->pid == getpid ());
|
||||
}
|
||||
g_object_unref (credentials);
|
||||
#else
|
||||
g_assert_error (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED);
|
||||
g_assert (credentials == NULL);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/* bring up a connection - don't accept it - this should fail
|
||||
*/
|
||||
|
Reference in New Issue
Block a user