Bug#581750: glib2.0: FTBFS on kfreebsd-*: error: 'SOL_SOCKET' undeclared
Julien Cristau
jcristau at debian.org
Sat May 15 21:57:42 UTC 2010
On Sat, May 15, 2010 at 16:02:29 +0200, Cyril Brulebois wrote:
> your package no longer builds on kfreebsd-*:
> | libtool: compile: gcc -DHAVE_CONFIG_H -I. -I/build/buildd-glib2.0_2.25.5-1-kfreebsd-i386-eQ8MPT/glib2.0-2.25.5/gio -I.. -DG_LOG_DOMAIN=\"GLib-GIO\" -I.. -I/build/buildd-glib2.0_2.25.5-1-kfreebsd-i386-eQ8MPT/glib2.0-2.25.5 -I/build/buildd-glib2.0_2.25.5-1-kfreebsd-i386-eQ8MPT/glib2.0-2.25.5/glib -I/build/buildd-glib2.0_2.25.5-1-kfreebsd-i386-eQ8MPT/glib2.0-2.25.5/gmodule -DG_ENABLE_DEBUG -DG_THREADS_MANDATORY -DG_DISABLE_DEPRECATED -DGIO_COMPILATION -DGIO_MODULE_DIR=\"/usr/lib/gio/modules\" -DG_DISABLE_SINGLE_INCLUDES -pthread -g -O2 -Wall -g -O2 -MT gunixcredentialsmessage.lo -MD -MP -MF .deps/gunixcredentialsmessage.Tpo -c /build/buildd-glib2.0_2.25.5-1-kfreebsd-i386-eQ8MPT/glib2.0-2.25.5/gio/gunixcredentialsmessage.c -fPIC -DPIC -o .libs/gunixcredentialsmessage.o
> | /build/buildd-glib2.0_2.25.5-1-kfreebsd-i386-eQ8MPT/glib2.0-2.25.5/gio/gunixcredentialsmessage.c: In function 'g_unix_credentials_message_get_level':
> | /build/buildd-glib2.0_2.25.5-1-kfreebsd-i386-eQ8MPT/glib2.0-2.25.5/gio/gunixcredentialsmessage.c:89: error: 'SOL_SOCKET' undeclared (first use in this function)
So fixing the ftbfs is easy (either put the SOL_SOCKET thing in a linux
ifdef, or include <sys/socket.h> unconditionally).
Making this stuff actually work on freebsd I'm not sure. The following
should basically work. Note that afaict the freebsd interface doesn't
allow faking ids, even for root, unlike linux. struct cmsgcred has a
field for uid and for euid, I'm not sure which is more appropriate.
This is the first time I'm looking at this interface, and I'm not
familiar with freebsd, so somebody should double-check.
Cheers,
Julien
diff --git a/configure.in b/configure.in
index 38288c3..e14d523 100644
--- a/configure.in
+++ b/configure.in
@@ -1009,6 +1009,8 @@ fi
AC_CHECK_FUNCS(getprotobyname_r endservent)
AC_CHECK_HEADERS([netdb.h wspiapi.h])
+AC_CHECK_MEMBERS([struct cmsgcred.cmcred_pid], [], [], $glib_inet_includes)
+
# For gio/libasyncns
if test $glib_native_win32 = no; then
AC_CHECK_FUNCS(strndup setresuid setreuid)
diff --git a/gio/gcredentials.c b/gio/gcredentials.c
index bcea1a4..644046a 100644
--- a/gio/gcredentials.c
+++ b/gio/gcredentials.c
@@ -22,15 +22,16 @@
#include "config.h"
+#ifdef __linux__
+#define _GNU_SOURCE
+#endif
+
#include <stdlib.h>
-#ifdef __linux__
-#define __USE_GNU
#include <sys/types.h>
#include <sys/socket.h>
#include <unistd.h>
#include <string.h>
-#endif
#include <gobject/gvaluecollector.h>
@@ -66,6 +67,8 @@ struct _GCredentialsPrivate
{
#ifdef __linux__
struct ucred native;
+#elif HAVE_STRUCT_CMSGCRED_CMCRED_PID
+ struct cmsgcred native;
#else
#warning Please add GCredentials support for your OS
guint foo;
@@ -103,6 +106,10 @@ g_credentials_init (GCredentials *credentials)
credentials->priv->native.pid = getpid ();
credentials->priv->native.uid = getuid ();
credentials->priv->native.gid = getgid ();
+#elif HAVE_STRUCT_CMSGCRED_CMCRED_PID
+ credentials->priv->native.cmcred_pid = getpid();
+ credentials->priv->native.cmcred_uid = getuid();
+ credentials->priv->native.cmcred_gid = getgid();
#endif
}
@@ -156,6 +163,16 @@ g_credentials_to_string (GCredentials *credentials)
g_string_append_printf (ret, "gid=%" G_GINT64_FORMAT ",", (gint64) credentials->priv->native.gid);
if (ret->str[ret->len - 1] == ',')
ret->str[ret->len - 1] = '\0';
+#elif HAVE_STRUCT_CMSGCRED_CMCRED_PID
+ g_string_append (ret, "bsd:");
+ if (credentials->priv->native.cmcred_pid != -1)
+ g_string_append_printf(ret, "pid=%" G_GINT64_FORMAT ",", (gint64) credentials->priv->native.cmcred_pid);
+ if (credentials->priv->native.cmcred_uid != -1)
+ g_string_append_printf(ret, "uid=%" G_GINT64_FORMAT ",", (gint64) credentials->priv->native.cmcred_uid);
+ if (credentials->priv->native.cmcred_gid != -1)
+ g_string_append_printf(ret, "gid=%" G_GINT64_FORMAT ",", (gint64) credentials->priv->native.cmcred_gid);
+ if (ret->str[ret->len - 1] == ',')
+ ret->str[ret->len - 1] = '\0';
#else
g_string_append (ret, "unknown");
#endif
@@ -196,6 +213,9 @@ g_credentials_is_same_user (GCredentials *credentials,
#ifdef __linux__
if (credentials->priv->native.uid == other_credentials->priv->native.uid)
ret = TRUE;
+#elif HAVE_STRUCT_CMSGCRED_CMCRED_PID
+ if (credentials->priv->native.cmcred_uid == other_credentials->priv->native.cmcred_uid)
+ ret = TRUE;
#else
g_set_error_literal (error,
G_IO_ERROR,
@@ -224,7 +244,7 @@ g_credentials_get_native (GCredentials *credentials)
gpointer ret;
g_return_val_if_fail (G_IS_CREDENTIALS (credentials), NULL);
-#ifdef __linux__
+#if defined(__linux__) || defined(HAVE_STRUCT_CMSGCRED_CMCRED_PID)
ret = &credentials->priv->native;
#else
ret = NULL;
@@ -250,8 +270,8 @@ void
g_credentials_set_native (GCredentials *credentials,
gpointer native)
{
-#ifdef __linux__
- memcpy (&credentials->priv->native, native, sizeof (struct ucred));
+#if defined(__linux__) || defined(HAVE_STRUCT_CMSGCRED_CMCRED_PID)
+ memcpy (&credentials->priv->native, native, sizeof (credentials->priv->native));
#else
g_warning ("g_credentials_set_native: Trying to set credentials but GLib has no support "
"for the native credentials type. Please add support.");
@@ -288,6 +308,8 @@ g_credentials_get_unix_user (GCredentials *credentials,
#ifdef __linux__
ret = credentials->priv->native.uid;
+#elif HAVE_STRUCT_CMSGCRED_CMCRED_PID
+ ret = credentials->priv->native.cmcred_uid;
#else
ret = -1;
g_set_error_literal (error,
@@ -331,6 +353,9 @@ g_credentials_set_unix_user (GCredentials *credentials,
#ifdef __linux__
credentials->priv->native.uid = uid;
ret = TRUE;
+#elif HAVE_STRUCT_CMSGCRED_CMCRED_PID
+ credentials->priv->native.cmcred_uid = uid;
+ ret = TRUE;
#else
g_set_error_literal (error,
G_IO_ERROR,
diff --git a/gio/gunixcredentialsmessage.c b/gio/gunixcredentialsmessage.c
index 15c4c96..41370f6 100644
--- a/gio/gunixcredentialsmessage.c
+++ b/gio/gunixcredentialsmessage.c
@@ -36,19 +36,23 @@
#ifdef __linux__
#define _GNU_SOURCE
-#define __USE_GNU
-#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
+#elif HAVE_STRUCT_CMSGCRED_CMCRED_PID
+
+#include <unistd.h>
+#define G_UNIX_CREDENTIALS_MESSAGE_SUPPORTED 1
+
#else
/* TODO: please add support for your UNIX flavor */
#define G_UNIX_CREDENTIALS_MESSAGE_SUPPORTED 0
#endif
+#include <sys/types.h>
+#include <sys/socket.h>
/* ---------------------------------------------------------------------------------------------------- */
#include <string.h>
@@ -78,6 +82,8 @@ g_unix_credentials_message_get_size (GSocketControlMessage *message)
{
#ifdef __linux__
return sizeof (struct ucred);
+#elif HAVE_STRUCT_CMSGCRED_CMCRED_PID
+ return sizeof (struct cmsgcred);
#else
return 0;
#endif
@@ -94,6 +100,8 @@ g_unix_credentials_message_get_msg_type (GSocketControlMessage *message)
{
#ifdef __linux__
return SCM_CREDENTIALS;
+#elif HAVE_STRUCT_CMSGCRED_CMCRED_PID
+ return SCM_CREDS;
#else
return 0;
#endif
@@ -135,6 +143,32 @@ g_unix_credentials_message_deserialize (gint level,
out:
;
}
+#elif HAVE_STRUCT_CMSGCRED_CMCRED_PID
+ {
+ GCredentials *credentials;
+ struct cmsgcred *cmsgcred;
+
+ if (level != SOL_SOCKET || type != SCM_CREDS)
+ goto out;
+
+ if (size != sizeof (struct cmsgcred))
+ {
+ g_warning ("Expected a struct cmsgcred (%" G_GSIZE_FORMAT " bytes) but "
+ "got %" G_GSIZE_FORMAT " bytes of data",
+ sizeof (struct cmsgcred),
+ size);
+ goto out;
+ }
+
+ cmsgcred = data;
+
+ credentials = g_credentials_new ();
+ g_credentials_set_native (credentials, cmsgcred);
+ message = g_unix_credentials_message_new_with_credentials (credentials);
+ g_object_unref (credentials);
+ out:
+ ;
+ }
#endif
return message;
@@ -147,6 +181,8 @@ g_unix_credentials_message_serialize (GSocketControlMessage *_message,
GUnixCredentialsMessage *message = G_UNIX_CREDENTIALS_MESSAGE (_message);
#ifdef __linux__
memcpy (data, g_credentials_get_native (message->priv->credentials), sizeof (struct ucred));
+#elif HAVE_STRUCT_CMSGCRED_CMCRED_PID
+ memcpy(data, g_credentials_get_native(message->priv->credentials), sizeof (struct cmsgcred));
#endif
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.alioth.debian.org/pipermail/pkg-gnome-maintainers/attachments/20100515/a6c3f0c3/attachment.pgp>
More information about the pkg-gnome-maintainers
mailing list