GNOME Bugzilla – Bug 628904
[PATCH] Add credential support for FreeBSD and fix a socket issue
Last modified: 2011-08-27 16:29:26 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.
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
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.
(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!
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.
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?
Please reopen a bug when you add a comment; otherwise it is unlikely to be noticed.
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?
** 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...
(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