Rewrite / add glib credentials support to OpenBSD.

Joint work with upstream.
This commit is contained in:
ajacoutot 2011-05-28 07:32:06 +00:00
parent a86c14c4aa
commit e336dd0283
10 changed files with 199 additions and 206 deletions

View File

@ -1,4 +1,4 @@
# $OpenBSD: Makefile,v 1.116 2011/05/27 08:25:14 ajacoutot Exp $
# $OpenBSD: Makefile,v 1.117 2011/05/28 07:32:06 ajacoutot Exp $
COMMENT-main= general-purpose utility library
COMMENT-docs= glib2 documentation
@ -8,7 +8,7 @@ DISTNAME= glib-${VERSION}
PKGNAME-main= glib2-${VERSION}
PKGNAME-docs= glib2-docs-${VERSION}
REVISION-main= 2
REVISION-main= 3
CATEGORIES= devel

View File

@ -1,4 +1,10 @@
$OpenBSD: patch-gio_gcredentials_c,v 1.1 2011/04/28 13:07:53 ajacoutot Exp $
$OpenBSD: patch-gio_gcredentials_c,v 1.2 2011/05/28 07:32:06 ajacoutot Exp $
From 77f4f5aa02458e6c7f909dc6087a39d9b75d0ba6 Mon Sep 17 00:00:00 2001
From: Antoine Jacoutot <ajacoutot@openbsd.org>
Date: Fri, 27 May 2011 13:51:08 +0000
Subject: Add glib credentials support to OpenBSD.
--- gio/gcredentials.c.orig Fri Nov 12 14:52:52 2010
+++ gio/gcredentials.c Wed Dec 8 08:36:10 2010
@@ -27,6 +27,11 @@

View File

@ -0,0 +1,34 @@
$OpenBSD: patch-gio_gdbusauth_c,v 1.1 2011/05/28 07:32:06 ajacoutot Exp $
From 77f4f5aa02458e6c7f909dc6087a39d9b75d0ba6 Mon Sep 17 00:00:00 2001
From: Antoine Jacoutot <ajacoutot@openbsd.org>
Date: Fri, 27 May 2011 13:51:08 +0000
Subject: Add glib credentials support to OpenBSD.
--- gio/gdbusauth.c.orig Sat May 21 05:29:51 2011
+++ gio/gdbusauth.c Fri May 27 15:42:09 2011
@@ -612,7 +612,7 @@ _g_dbus_auth_run_client (GDBusAuth *auth,
g_data_input_stream_set_newline_type (dis, G_DATA_STREAM_NEWLINE_TYPE_CR_LF);
#ifdef G_OS_UNIX
- if (G_IS_UNIX_CONNECTION (auth->priv->stream) && g_unix_credentials_message_is_supported ())
+ if (G_IS_UNIX_CONNECTION (auth->priv->stream))
{
credentials = g_credentials_new ();
if (!g_unix_connection_send_credentials (G_UNIX_CONNECTION (auth->priv->stream),
@@ -989,13 +989,13 @@ _g_dbus_auth_run_server (GDBusAuth *auth,
/* first read the NUL-byte (TODO: read credentials if using a unix domain socket) */
#ifdef G_OS_UNIX
- if (G_IS_UNIX_CONNECTION (auth->priv->stream) && g_unix_credentials_message_is_supported ())
+ if (G_IS_UNIX_CONNECTION (auth->priv->stream))
{
local_error = NULL;
credentials = g_unix_connection_receive_credentials (G_UNIX_CONNECTION (auth->priv->stream),
cancellable,
&local_error);
- if (credentials == NULL)
+ if (credentials == NULL && !g_error_matches (local_error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED))
{
g_propagate_error (error, local_error);
goto out;

View File

@ -1,11 +1,17 @@
$OpenBSD: patch-gio_gioenums_h,v 1.1 2011/04/28 13:07:53 ajacoutot Exp $
--- gio/gioenums.h.orig Thu Apr 14 00:55:29 2011
+++ gio/gioenums.h Wed Apr 27 13:31:03 2011
$OpenBSD: patch-gio_gioenums_h,v 1.2 2011/05/28 07:32:06 ajacoutot Exp $
From 77f4f5aa02458e6c7f909dc6087a39d9b75d0ba6 Mon Sep 17 00:00:00 2001
From: Antoine Jacoutot <ajacoutot@openbsd.org>
Date: Fri, 27 May 2011 13:51:08 +0000
Subject: Add glib credentials support to OpenBSD.
--- gio/gioenums.h.orig Sat May 21 05:29:24 2011
+++ gio/gioenums.h Fri May 27 15:47:24 2011
@@ -1214,6 +1214,7 @@ typedef enum
* @G_CREDENTIALS_TYPE_INVALID: Indicates an invalid native credential type.
* @G_CREDENTIALS_TYPE_LINUX_UCRED: The native credentials type is a <type>struct ucred</type>.
* @G_CREDENTIALS_TYPE_FREEBSD_CMSGCRED: The native credentials type is a <type>struct cmsgcred</type>.
+ * @G_CREDENTIALS_TYPE_OPENBSD_SOCKPEERCRED: The native credentials type is a <type>struct sockpeercred</type>.
+ * @G_CREDENTIALS_TYPE_OPENBSD_SOCKPEERCRED: The native credentials type is a <type>struct sockpeercred</type>. Added in 2.30.
*
* Enumeration describing different kinds of native credential types.
*

View File

@ -1,6 +1,12 @@
$OpenBSD: patch-gio_gioenumtypes_c,v 1.1 2011/04/28 13:07:53 ajacoutot Exp $
--- gio/gioenumtypes.c.orig Thu Apr 14 00:59:31 2011
+++ gio/gioenumtypes.c Wed Apr 27 13:31:03 2011
$OpenBSD: patch-gio_gioenumtypes_c,v 1.2 2011/05/28 07:32:06 ajacoutot Exp $
From 77f4f5aa02458e6c7f909dc6087a39d9b75d0ba6 Mon Sep 17 00:00:00 2001
From: Antoine Jacoutot <ajacoutot@openbsd.org>
Date: Fri, 27 May 2011 13:51:08 +0000
Subject: Add glib credentials support to OpenBSD.
--- gio/gioenumtypes.c.orig Sat May 21 06:17:13 2011
+++ gio/gioenumtypes.c Thu May 26 08:40:57 2011
@@ -1161,6 +1161,7 @@ g_credentials_type_get_type (void)
{ G_CREDENTIALS_TYPE_INVALID, "G_CREDENTIALS_TYPE_INVALID", "invalid" },
{ G_CREDENTIALS_TYPE_LINUX_UCRED, "G_CREDENTIALS_TYPE_LINUX_UCRED", "linux-ucred" },

View File

@ -0,0 +1,40 @@
$OpenBSD: patch-gio_gsocket_c,v 1.1 2011/05/28 07:32:06 ajacoutot Exp $
From 77f4f5aa02458e6c7f909dc6087a39d9b75d0ba6 Mon Sep 17 00:00:00 2001
From: Antoine Jacoutot <ajacoutot@openbsd.org>
Date: Fri, 27 May 2011 13:51:08 +0000
Subject: Add glib credentials support to OpenBSD.
--- gio/gsocket.c.orig Sat May 21 05:29:24 2011
+++ gio/gsocket.c Fri May 27 15:43:31 2011
@@ -3514,11 +3514,16 @@ g_socket_get_credentials (GSocket *socket,
ret = NULL;
-#ifdef __linux__
+#if defined(__linux__) || defined(__OpenBSD__)
{
- struct ucred native_creds;
socklen_t optlen;
+#if defined(__linux__)
+ struct ucred native_creds;
optlen = sizeof (struct ucred);
+#elif defined(__OpenBSD__)
+ struct sockpeercred native_creds;
+ optlen = sizeof (struct sockpeercred);
+#endif
if (getsockopt (socket->priv->fd,
SOL_SOCKET,
SO_PEERCRED,
@@ -3536,7 +3541,11 @@ g_socket_get_credentials (GSocket *socket,
{
ret = g_credentials_new ();
g_credentials_set_native (ret,
+#if defined(__linux__)
G_CREDENTIALS_TYPE_LINUX_UCRED,
+#elif defined(__OpenBSD__)
+ G_CREDENTIALS_TYPE_OPENBSD_SOCKPEERCRED,
+#endif
&native_creds);
}
}

View File

@ -1,133 +1,119 @@
$OpenBSD: patch-gio_gunixconnection_c,v 1.2 2011/05/23 16:36:13 ajacoutot Exp $
$OpenBSD: patch-gio_gunixconnection_c,v 1.3 2011/05/28 07:32:06 ajacoutot Exp $
XXX
Workaround the fact that we cannot pass SCM_CREDS over unix sockets:
implement the "intended" SCM_CREDS stack as if we had support for that
in the kernel (by-pass it almost completely).
send/recv a single null byte without creds, but on recv, just do a
getsockopt(SO_PEERCRED) and return that as if it coming from the cmsg.
This works as long as creds are not retreived from an fd which has
already been handed over to a different process via SCM_RIGHTS. It will
probably not be enough in the future but we'll see then.
From 77f4f5aa02458e6c7f909dc6087a39d9b75d0ba6 Mon Sep 17 00:00:00 2001
From: Antoine Jacoutot <ajacoutot@openbsd.org>
Date: Fri, 27 May 2011 13:51:08 +0000
Subject: Add glib credentials support to OpenBSD.
--- gio/gunixconnection.c.orig Sat May 21 05:29:24 2011
+++ gio/gunixconnection.c Mon May 23 18:20:08 2011
@@ -42,7 +42,7 @@
#include <gio/gsocket.h>
#include <unistd.h>
-#ifdef __linux__
+#if defined(__linux__) || defined(__OpenBSD__)
/* for getsockopt() and setsockopt() */
#include <sys/types.h> /* See NOTES */
#include <sys/socket.h>
@@ -328,8 +328,10 @@ g_unix_connection_send_credentials (GUnixConnection
GCancellable *cancellable,
GError **error)
{
+#ifndef __OpenBSD__
GCredentials *credentials;
GSocketControlMessage *scm;
+#endif
GSocket *socket;
+++ gio/gunixconnection.c Fri May 27 15:57:02 2011
@@ -334,6 +334,7 @@ g_unix_connection_send_credentials (GUnixConnection
gboolean ret;
GOutputVector vector;
@@ -340,18 +342,28 @@ g_unix_connection_send_credentials (GUnixConnection
guchar nul_byte[1] = {'\0'};
+ gint num_messages;
ret = FALSE;
+#ifndef __OpenBSD__
credentials = g_credentials_new ();
+ scm = g_unix_credentials_message_new_with_credentials (credentials);
+#endif
g_return_val_if_fail (G_IS_UNIX_CONNECTION (connection), FALSE);
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
@@ -344,14 +345,25 @@ g_unix_connection_send_credentials (GUnixConnection
vector.buffer = &nul_byte;
vector.size = 1;
+#ifndef __OpenBSD__
scm = g_unix_credentials_message_new_with_credentials (credentials);
+#endif
- scm = g_unix_credentials_message_new_with_credentials (credentials);
+
+ if (g_unix_credentials_message_is_supported ())
+ {
+ scm = g_unix_credentials_message_new_with_credentials (credentials);
+ num_messages = 1;
+ }
+ else
+ {
+ scm = NULL;
+ num_messages = 0;
+ }
+
g_object_get (connection, "socket", &socket, NULL);
if (g_socket_send_message (socket,
NULL, /* address */
&vector,
1,
+#ifndef __OpenBSD__
&scm,
1,
+#else
+ NULL,
+ 0,
+#endif
- 1,
+ num_messages,
G_SOCKET_MSG_NONE,
cancellable,
error) != 1)
@@ -364,8 +376,10 @@ g_unix_connection_send_credentials (GUnixConnection
@@ -364,7 +376,8 @@ g_unix_connection_send_credentials (GUnixConnection
out:
g_object_unref (socket);
+#ifndef __OpenBSD__
g_object_unref (scm);
- g_object_unref (scm);
+ if (scm != NULL)
+ g_object_unref (scm);
g_object_unref (credentials);
+#endif
return ret;
}
@@ -406,6 +420,10 @@ g_unix_connection_receive_credentials (GUnixConnection
#ifdef __linux__
gboolean turn_off_so_passcreds;
#endif
+#ifdef __OpenBSD__
+ struct sockpeercred cred;
+ socklen_t len;
+#endif
g_return_val_if_fail (G_IS_UNIX_CONNECTION (connection), NULL);
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
@@ -497,16 +515,25 @@ g_unix_connection_receive_credentials (GUnixConnection
@@ -497,27 +510,46 @@ g_unix_connection_receive_credentials (GUnixConnection
goto out;
}
+#ifndef __OpenBSD__
if (nscm != 1)
+#else
+ if (nscm != 0)
+#endif
- if (nscm != 1)
+ if (g_unix_credentials_message_is_supported ())
{
g_set_error (error,
G_IO_ERROR,
G_IO_ERROR_FAILED,
+#ifndef __OpenBSD__
_("Expecting 1 control message, got %d"),
+#else
+ _("Expecting 0 control message, got %d"),
+#endif
nscm);
goto out;
- g_set_error (error,
- G_IO_ERROR,
- G_IO_ERROR_FAILED,
- _("Expecting 1 control message, got %d"),
- nscm);
- goto out;
- }
+ if (nscm != 1)
+ {
+ g_set_error (error,
+ G_IO_ERROR,
+ G_IO_ERROR_FAILED,
+ _("Expecting 1 control message, got %d"),
+ nscm);
+ goto out;
+ }
- if (!G_IS_UNIX_CREDENTIALS_MESSAGE (scms[0]))
+ if (!G_IS_UNIX_CREDENTIALS_MESSAGE (scms[0]))
+ {
+ g_set_error_literal (error,
+ G_IO_ERROR,
+ G_IO_ERROR_FAILED,
+ _("Unexpected type of ancillary data"));
+ goto out;
+ }
+
+ ret = g_unix_credentials_message_get_credentials (G_UNIX_CREDENTIALS_MESSAGE (scms[0]));
+ g_object_ref (ret);
+ }
+ else
{
- g_set_error_literal (error,
- G_IO_ERROR,
- G_IO_ERROR_FAILED,
- _("Unexpected type of ancillary data"));
- goto out;
+ if (nscm != 0)
+ {
+ g_set_error (error,
+ G_IO_ERROR,
+ G_IO_ERROR_FAILED,
+ _("Not expecting control message, but got %d"),
+ nscm);
+ goto out;
+ }
+ else
+ {
+ ret = g_socket_get_credentials (socket, error);
+ }
}
+#ifndef __OpenBSD__
if (!G_IS_UNIX_CREDENTIALS_MESSAGE (scms[0]))
{
g_set_error_literal (error,
@@ -518,6 +545,21 @@ g_unix_connection_receive_credentials (GUnixConnection
ret = g_unix_credentials_message_get_credentials (G_UNIX_CREDENTIALS_MESSAGE (scms[0]));
g_object_ref (ret);
+#else
+ len = sizeof(cred);
+ if (getsockopt(g_socket_get_fd(socket),
+ SOL_SOCKET, SO_PEERCRED, &cred, &len) == -1) {
+ g_set_error (error,
+ G_IO_ERROR,
+ g_io_error_from_errno (errno),
+ _("Error : getsockopt(SO_PEERCRED): %s"),
+ strerror (errno));
+ goto out;
+ }
+
+ ret = g_credentials_new();
+ g_credentials_set_native(ret, G_CREDENTIALS_TYPE_OPENBSD_SOCKPEERCRED, &cred);
+#endif
-
- ret = g_unix_credentials_message_get_credentials (G_UNIX_CREDENTIALS_MESSAGE (scms[0]));
- g_object_ref (ret);
out:

View File

@ -1,91 +0,0 @@
$OpenBSD: patch-gio_gunixcredentialsmessage_c,v 1.1 2011/04/28 13:07:53 ajacoutot Exp $
--- gio/gunixcredentialsmessage.c.orig Fri Nov 12 14:52:52 2010
+++ gio/gunixcredentialsmessage.c Wed Dec 8 00:11:15 2010
@@ -53,6 +53,14 @@
#include <unistd.h>
#include <fcntl.h>
#define G_UNIX_CREDENTIALS_MESSAGE_SUPPORTED 1
+
+#elif defined(__OpenBSD__)
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+#include <unistd.h>
+#include <fcntl.h>
+#define G_UNIX_CREDENTIALS_MESSAGE_SUPPORTED 1
#else
/* TODO: please add support for your UNIX flavor */
#define G_UNIX_CREDENTIALS_MESSAGE_SUPPORTED 0
@@ -88,6 +96,8 @@ g_unix_credentials_message_get_size (GSocketControlMes
return sizeof (struct ucred);
#elif defined(__FreeBSD__)
return sizeof (struct cmsgcred);
+#elif defined(__OpenBSD__)
+ return sizeof (struct sockpeercred);
#else
return 0;
#endif
@@ -100,6 +110,8 @@ g_unix_credentials_message_get_level (GSocketControlMe
return SOL_SOCKET;
#elif defined(__FreeBSD__)
return SOL_SOCKET;
+#elif defined(__OpenBSD__)
+ return SOL_SOCKET;
#else
return 0;
#endif
@@ -112,6 +124,8 @@ g_unix_credentials_message_get_msg_type (GSocketContro
return SCM_CREDENTIALS;
#elif defined(__FreeBSD__)
return SCM_CREDS;
+#elif defined(__OpenBSD__)
+ return SCM_CREDS;
#else
return 0;
#endif
@@ -180,6 +194,32 @@ g_unix_credentials_message_deserialize (gint level
out:
;
}
+#elif defined(__OpenBSD__)
+ {
+ GCredentials *credentials;
+ struct sockpeercred *cr;
+
+ if (level != SOL_SOCKET || type != SCM_CREDS)
+ goto out;
+
+ if (size != sizeof (struct sockpeercred))
+ {
+ g_warning ("Expected a struct sockpeercred (%" G_GSIZE_FORMAT " bytes) but "
+ "got %" G_GSIZE_FORMAT " bytes of data",
+ sizeof (struct sockpeercred),
+ size);
+ goto out;
+ }
+
+ cr = data;
+
+ credentials = g_credentials_new ();
+ g_credentials_set_native (credentials, G_CREDENTIALS_TYPE_OPENBSD_SOCKPEERCRED, cr);
+ message = g_unix_credentials_message_new_with_credentials (credentials);
+ g_object_unref (credentials);
+ out:
+ ;
+ }
#endif
return message;
@@ -200,7 +240,11 @@ g_unix_credentials_message_serialize (GSocketControlMe
g_credentials_get_native (message->priv->credentials,
G_CREDENTIALS_TYPE_FREEBSD_CMSGCRED),
sizeof (struct cmsgcred));
-
+#elif defined(__OpenBSD__)
+ memcpy (data,
+ g_credentials_get_native (message->priv->credentials,
+ G_CREDENTIALS_TYPE_OPENBSD_SOCKPEERCRED),
+ sizeof (struct sockpeercred));
#endif
}

View File

@ -1,6 +1,9 @@
$OpenBSD: patch-gio_tests_gdbus-connection_c,v 1.1 2010/12/29 09:58:45 sebastia Exp $
$OpenBSD: patch-gio_tests_gdbus-connection_c,v 1.2 2011/05/28 07:32:06 ajacoutot Exp $
Fix for gcc-2.95
From ce0f7cafa1746a94f90b74860c2890b6c18ca385 Mon Sep 17 00:00:00 2001
From: Antoine Jacoutot <ajacoutot@bsdfrog.org>
Date: Mon, 23 May 2011 17:11:10 +0000
Subject: Fix build with gcc-2.*.
--- gio/tests/gdbus-connection.c.orig Wed Dec 29 09:41:16 2010
+++ gio/tests/gdbus-connection.c Wed Dec 29 09:48:35 2010

View File

@ -1,6 +1,9 @@
$OpenBSD: patch-gio_tests_memory-output-stream_c,v 1.2 2010/09/30 07:17:19 ajacoutot Exp $
$OpenBSD: patch-gio_tests_memory-output-stream_c,v 1.3 2011/05/28 07:32:06 ajacoutot Exp $
Fix build with GCC2.
From ce0f7cafa1746a94f90b74860c2890b6c18ca385 Mon Sep 17 00:00:00 2001
From: Antoine Jacoutot <ajacoutot@bsdfrog.org>
Date: Mon, 23 May 2011 17:11:10 +0000
Subject: Fix build with gcc-2.*.
--- gio/tests/memory-output-stream.c.orig Mon Aug 9 15:34:46 2010
+++ gio/tests/memory-output-stream.c Mon Sep 27 14:42:36 2010