diff options
author | Simon McVittie <smcv@collabora.com> | 2019-05-13 11:32:24 +0000 |
---|---|---|
committer | Simon McVittie <smcv@collabora.com> | 2019-05-13 11:32:24 +0000 |
commit | 6884f63e0ebca521dec3fab1b6320741259530d3 (patch) | |
tree | cc008ad3a4554c874480971b457fcbf61315438a /bus | |
parent | 5619f03984d1a91d2d665de3a19251266afdf785 (diff) | |
parent | 9e0fd2fbbfd1a86f9c6cf6d909054b806aabde36 (diff) | |
download | dbus-6884f63e0ebca521dec3fab1b6320741259530d3.tar.gz |
Merge branch 'unix-gids' into 'master'
Add UnixGroupIDs to connection credentials
See merge request dbus/dbus!105
Fixes: dbus/dbus#196
Diffstat (limited to 'bus')
-rw-r--r-- | bus/driver.c | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/bus/driver.c b/bus/driver.c index 267c881d..3898cfd6 100644 --- a/bus/driver.c +++ b/bus/driver.c @@ -1905,6 +1905,59 @@ bus_driver_handle_get_connection_selinux_security_context (DBusConnection *conne } /* + * Write the unix group ids of credentials @credentials, if available, into + * the a{sv} @asv_iter. Return #FALSE on OOM. + */ +static dbus_bool_t +bus_driver_credentials_fill_unix_gids (DBusCredentials *credentials, + DBusMessageIter *asv_iter) +{ + const dbus_gid_t *gids = NULL; + size_t n_gids = 0; + + if (!_dbus_credentials_get_unix_gids (credentials, &gids, &n_gids)) + return TRUE; + + if (sizeof (dbus_gid_t) == sizeof (dbus_uint32_t)) + { + return _dbus_asv_add_fixed_array (asv_iter, "UnixGroupIDs", + DBUS_TYPE_UINT32, gids, n_gids); + } + else + { + /* we can't represent > 32-bit uids; if your system needs them, please + * add UnixGroupIDs64 to the spec or something */ + dbus_uint32_t *gids_u32; + size_t i; + dbus_bool_t result; + + gids_u32 = dbus_new (dbus_uint32_t, n_gids); + if (gids_u32 == NULL) + return FALSE; + + for (i = 0; i < n_gids; i++) + { + if (gids[i] > _DBUS_UINT32_MAX) + { + /* At least one gid is unrepresentable, so behave as though + * we didn't know the group IDs at all (not an error, just + * success with less information) */ + dbus_free (gids_u32); + return TRUE; + } + gids_u32[i] = gids[i]; + } + + result = _dbus_asv_add_fixed_array (asv_iter, "UnixGroupIDs", + DBUS_TYPE_UINT32, gids_u32, n_gids); + + dbus_free (gids_u32); + + return result; + } +} + +/* * Write the credentials of connection @conn (or the bus daemon itself, * if @conn is #NULL) into the a{sv} @asv_iter. Return #FALSE on OOM. */ @@ -1943,6 +1996,10 @@ bus_driver_fill_connection_credentials (DBusCredentials *credentials, !_dbus_asv_add_uint32 (asv_iter, "UnixUserID", uid)) return FALSE; + if (credentials != NULL && + !bus_driver_credentials_fill_unix_gids (credentials, asv_iter)) + return FALSE; + if (windows_sid != NULL) { DBusString str; |