summaryrefslogtreecommitdiff
path: root/lib/gibber
diff options
context:
space:
mode:
authorSimon McVittie <simon.mcvittie@collabora.co.uk>2010-05-07 14:38:38 +0100
committerSimon McVittie <simon.mcvittie@collabora.co.uk>2010-05-07 14:38:38 +0100
commit10e1d2758dbcdf9c04c2ca96a42a2bf357eba69c (patch)
tree422337d6e520f3f7b6a151e5123963efee87b63d /lib/gibber
parentc826be427182246f0645d42a73f4f38ee3d361c5 (diff)
downloadtelepathy-salut-10e1d2758dbcdf9c04c2ca96a42a2bf357eba69c.tar.gz
fd.o#22970: GibberUnixTransport: make credential-passing support optional and detectable
Our implementation only works for Linux so far, so we need to be able to avoid advertising credential-passing on e.g. Darwin. Patches to the implementation were copied from Gabble, fd.o #22968; patches to the tests are new.
Diffstat (limited to 'lib/gibber')
-rw-r--r--lib/gibber/gibber-unix-transport.c47
-rw-r--r--lib/gibber/gibber-unix-transport.h2
-rw-r--r--lib/gibber/tests/check-gibber-unix-transport.c20
3 files changed, 66 insertions, 3 deletions
diff --git a/lib/gibber/gibber-unix-transport.c b/lib/gibber/gibber-unix-transport.c
index 244f4683..7c800d8c 100644
--- a/lib/gibber/gibber-unix-transport.c
+++ b/lib/gibber/gibber-unix-transport.c
@@ -194,6 +194,17 @@ gibber_unix_transport_new_from_fd (int fd)
return transport;
}
+/* Patches that reimplement these functions for non-Linux would be welcome
+ * (please file a bug) */
+
+#if defined(__linux__)
+
+gboolean
+gibber_unix_transport_supports_credentials (void)
+{
+ return TRUE;
+}
+
gboolean
gibber_unix_transport_send_credentials (GibberUnixTransport *transport,
const guint8 *data,
@@ -356,3 +367,39 @@ gibber_unix_transport_recv_credentials (GibberUnixTransport *self,
priv->recv_creds_data = user_data;
return TRUE;
}
+
+#else /* OSs where we have no implementation */
+
+gboolean
+gibber_unix_transport_supports_credentials (void)
+{
+ return FALSE;
+}
+
+gboolean
+gibber_unix_transport_recv_credentials (GibberUnixTransport *self,
+ GibberUnixTransportRecvCredentialsCb callback,
+ gpointer user_data)
+{
+ DEBUG ("stub implementation, failing");
+ return FALSE;
+}
+
+gboolean
+gibber_unix_transport_send_credentials (GibberUnixTransport *transport,
+ const guint8 *data,
+ gsize size)
+{
+ DEBUG ("stub implementation, failing");
+ return FALSE;
+}
+
+static GibberFdIOResult
+gibber_unix_transport_read (GibberFdTransport *transport,
+ GIOChannel *channel,
+ GError **error)
+{
+ return gibber_fd_transport_read (transport, channel, error);
+}
+
+#endif
diff --git a/lib/gibber/gibber-unix-transport.h b/lib/gibber/gibber-unix-transport.h
index b89a0dd5..3aad8d47 100644
--- a/lib/gibber/gibber-unix-transport.h
+++ b/lib/gibber/gibber-unix-transport.h
@@ -79,6 +79,8 @@ GType gibber_unix_transport_get_type (void);
(G_TYPE_INSTANCE_GET_CLASS ((obj), GIBBER_TYPE_UNIX_TRANSPORT, \
GibberUnixTransportClass))
+gboolean gibber_unix_transport_supports_credentials (void);
+
GibberUnixTransport * gibber_unix_transport_new (void);
GibberUnixTransport * gibber_unix_transport_new_from_fd (int fd);
diff --git a/lib/gibber/tests/check-gibber-unix-transport.c b/lib/gibber/tests/check-gibber-unix-transport.c
index 409b6e4b..6a048fef 100644
--- a/lib/gibber/tests/check-gibber-unix-transport.c
+++ b/lib/gibber/tests/check-gibber-unix-transport.c
@@ -50,6 +50,7 @@ new_connection_cb (GibberListener *listener,
guint size,
GMainLoop *loop)
{
+#if defined(__linux__)
int fd, opt, ret;
struct iovec iov;
struct msghdr msg;
@@ -58,12 +59,14 @@ new_connection_cb (GibberListener *listener,
struct cmsghdr *ch;
struct ucred *cred;
gchar buffer[128];
+#endif
got_connection = TRUE;
/* Block receiving so the data won't be consummed by transport's GIOSource */
gibber_transport_block_receiving (connection, TRUE);
+#if defined(__linux__)
g_assert (gibber_unix_transport_send_credentials (unix_transport,
(guint8 *) DATA, strlen (DATA) + 1));
@@ -96,6 +99,10 @@ new_connection_cb (GibberListener *listener,
g_assert (cred->pid == getpid ());
g_assert (cred->uid == getuid ());
g_assert (cred->gid == getgid ());
+#else /* not Linux */
+ g_assert (!gibber_unix_transport_send_credentials (unix_transport,
+ (guint8 *) DATA, strlen (DATA) + 1));
+#endif
g_main_loop_quit (loop);
}
@@ -137,7 +144,6 @@ START_TEST (test_send_credentials)
g_main_loop_unref (mainloop);
} END_TEST
-
static void
get_credentials_cb (GibberUnixTransport *transport,
GibberBuffer *buffer,
@@ -165,11 +171,17 @@ receive_new_connection_cb (GibberListener *listener,
guint size,
GMainLoop *loop)
{
- gibber_unix_transport_recv_credentials (unix_transport,
+ gboolean ok;
+
+ ok = gibber_unix_transport_recv_credentials (unix_transport,
get_credentials_cb, loop);
- gibber_unix_transport_send_credentials (GIBBER_UNIX_TRANSPORT (connection),
+ g_assert (ok == gibber_unix_transport_supports_credentials ());
+
+ ok = gibber_unix_transport_send_credentials (GIBBER_UNIX_TRANSPORT (connection),
(guint8 *) DATA, strlen (DATA));
+
+ g_assert (ok == gibber_unix_transport_supports_credentials ());
}
START_TEST (test_receive_credentials)
@@ -199,10 +211,12 @@ START_TEST (test_receive_credentials)
ret = gibber_unix_transport_connect (unix_transport, path, &error);
fail_if (ret != TRUE);
+#if defined(__linux__)
if (!received_credentials)
g_main_loop_run (mainloop);
fail_if (!received_credentials, "Failed to receive credentials");
+#endif
g_object_unref (listener_unix);
g_object_unref (unix_transport);