After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 628904 - [PATCH] Add credential support for FreeBSD and fix a socket issue
[PATCH] Add credential support for FreeBSD and fix a socket issue
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: gio
2.25.x
Other FreeBSD
: Normal critical
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2010-09-06 17:29 UTC by Joe Marcus Clarke
Modified: 2011-08-27 16:29 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Add credential support for FreeBSD, and fix a socket problem (8.60 KB, patch)
2010-09-06 17:29 UTC, Joe Marcus Clarke
none Details | Review

Description Joe Marcus Clarke 2010-09-06 17:29:30 UTC
Created attachment 169594 [details] [review]
Add credential support for FreeBSD, and fix a socket problem

The attached patch adds UNIX credential support for FreeBSD as well as fixes a problem with sending messages on sockets when the control portion is empty.  Malloc on FreeBSD returns a non-NULL pointer when asked to allocated 0 bytes.  I imagine other platforms may be affected by this as well.
Comment 1 David Zeuthen (not reading bugmail) 2010-09-07 00:33:53 UTC
Patch generally looks good (just glanced, don't have time for a full review now) - though.. the gio/gioenumtypes.c hunk is unnecessary because that file is generated. I'm curious - does this patch make GDBus work on FreeBSD? (related: does the test suite pass?) Thanks, David
Comment 2 Joe Marcus Clarke 2010-09-07 00:36:19 UTC
Yes, this patch is absolutely required to make GDBus work on FreeBSD.  With it, GNOME 2.31 starts and seems to work.  I haven't run any test suites yet, but I think they should work.  The only thing I couldn't implement is the generic interface to get socket credentials.  That requires a two-way street on FreeBSD.  One end writes the credential message, and the other end reads it.
Comment 3 David Zeuthen (not reading bugmail) 2010-09-07 01:18:12 UTC
(In reply to comment #2)
> Yes, this patch is absolutely required to make GDBus work on FreeBSD.  With it,
> GNOME 2.31 starts and seems to work.

Cool.

>  I haven't run any test suites yet, but I
> think they should work.  The only thing I couldn't implement is the generic
> interface to get socket credentials. 

g_socket_get_credentials(), right? That's fine, we don't guarantee that it actually works; it's fine to return G_IO_ERROR_NOT_SUPPORTED.

> That requires a two-way street on
> FreeBSD.  One end writes the credential message, and the other end reads it.

Right, that's g_unix_connection_{send,receive}_credentials() which must always work on POSIX (it's implemented one way or another; e.g. either by passing creds or by using things like g_socket_get_credentials()).


I'll commit the patch tomorrow. Thanks for making sure it works on FreeBSD!
Comment 4 David Zeuthen (not reading bugmail) 2010-09-09 18:20:25 UTC
Committed with a minor change (a printed warning references 'struct ucred' when you meant 'struct cmsgcred' instead):

http://git.gnome.org/browse/glib/commit/?id=964eb62343b53cf9172d409adacbb58d78896092

Thanks.
Comment 5 Henry Hu 2011-08-12 10:48:05 UTC
Hello, I have a small problem about this part:
@@ -140,6 +153,33 @@ g_unix_credentials_message_deserialize (
  out:
     ;
   }
+#elif defined(__FreeBSD__)
+  {
+    GCredentials *credentials;
+    struct cmsgcred *cred;
+
+    if (level != SOL_SOCKET || type != SCM_CREDS)
+      {
+        goto out;
+      }
+    if (size < CMSG_LEN (sizeof *cred))
+      {
+        g_warning ("Expected a struct ucred (%" G_GSIZE_FORMAT " bytes) but "
+                   "got %" G_GSIZE_FORMAT " bytes of data",
+                   CMSG_LEN (sizeof *cred),
+                   size);
+        goto out;
+      }
+
+    cred = data;
+
+    credentials = g_credentials_new ();
+    g_credentials_set_native (credentials, G_CREDENTIALS_TYPE_FREEBSD_CMSGCRED, cred);
+    message = g_unix_credentials_message_new_with_credentials (credentials);
+    g_object_unref (credentials);
+ out:
+    ;
+  }
 #endif

Why you need CMSG_LEN()? This adds extra sizeof(struct cmsghdr) bytes to the size to check. However, the corresponding Linux code does not have this one.

Also considering g_unix_credentials_message_serialize(), there is no CMSG_LEN() there. Why do you need it in g_unix_credentials_message_deserialize()?

The problem is that I am testing new ibus (1.3.99.20110419.tar.gz) under FreeBSD 8.2-STABLE. I see warning messages:

(ibus-daemon:97531): GLib-GIO-WARNING **: Expected a struct cmsgcred (96 bytes) but got 84 bytes of data

(ibus-daemon:97531): GLib-GIO-WARNING **: unknown control message type 65535:3

They repeated many times. sizeof(struct cmsgcred) is 84, and CMSG_LEN(sizeof(struct cmsgcred)) is 96. And ibus does not start correctly.
After I removed the CMSG_LEN()s in g_unix_credentials_message_deserialize(), it works.

So I suspect that this is a problem in this commit?
Comment 6 Matthias Clasen 2011-08-14 04:45:53 UTC
Please reopen a bug when you add a comment; otherwise it is unlikely to be noticed.
Comment 7 Dan Winship 2011-08-23 23:43:56 UTC
Yeah, the CMSG_LEN() definitely seems wrong.

(In reply to comment #2)
> I haven't run any test suites yet, but I
> think they should work.

Famous last words... Henry (or Joe), can you try "make check" in gio/tests and see if any more changes are needed?
Comment 8 Henry Hu 2011-08-25 22:07:32 UTC
**
ERROR:gsettings.c:646:test_l10n: assertion failed (str == "Unbenannt"): ("Unnamed" == "Unbenannt")
  /gsettings/no-path:                                                  OK
  /gsettings/basic-types:                                              OK
  /gsettings/complex-types:                                            OK
  /gsettings/changes:                                                  OK
  /gsettings/l10n:                                                     FAIL
GTester: last random seed: R02S3e750f50f305c01eb71f4ab7d1f1b72c


It fails in gsettings...
Comment 9 Dan Winship 2011-08-27 16:26:28 UTC
(In reply to comment #8)
> **
> ERROR:gsettings.c:646:test_l10n: assertion failed (str == "Unbenannt"):
> ("Unnamed" == "Unbenannt")

hm... that passes for me. Anyway, I'm committing fixes for this and a few other problems