sd-bus: given that the kernel now passes the auxgroups list as 32bit array to us, no need to convert to uid_t manually

This way, we can save one allocation and avoid copying the array
unnecesarily.
This commit is contained in:
Lennart Poettering 2014-11-26 14:59:12 +01:00
parent 8514b67754
commit e12d81ae80
3 changed files with 17 additions and 25 deletions

View File

@ -402,6 +402,10 @@ static int bus_populate_creds_from_items(
uint64_t m;
int r;
assert(bus);
assert(info);
assert(c);
KDBUS_ITEM_FOREACH(item, info, items) {
switch (item->type) {
@ -590,18 +594,18 @@ static int bus_populate_creds_from_items(
case KDBUS_ITEM_AUXGROUPS:
if (mask & SD_BUS_CREDS_SUPPLEMENTARY_GIDS) {
size_t i, n;
uid_t *u;
size_t n;
uid_t *g;
n = (item->size - offsetof(struct kdbus_item, data64)) / sizeof(uint64_t);
u = new(uid_t, n);
if (!u)
assert_cc(sizeof(gid_t) == sizeof(uint32_t));
n = (item->size - offsetof(struct kdbus_item, data32)) / sizeof(uint32_t);
g = newdup(gid_t, item->data32, n);
if (!g)
return -ENOMEM;
for (i = 0; i < n; i++)
u[i] = (uid_t) item->data64[i];
c->supplementary_gids = u;
free(c->supplementary_gids);
c->supplementary_gids = g;
c->n_supplementary_gids = n;
c->mask |= SD_BUS_CREDS_SUPPLEMENTARY_GIDS;

View File

@ -53,8 +53,6 @@ void bus_creds_done(sd_bus_creds *c) {
strv_free(c->cmdline_array);
strv_free(c->well_known_names);
free(c->supplementary_gids);
}
_public_ sd_bus_creds *sd_bus_creds_ref(sd_bus_creds *c) {
@ -97,6 +95,7 @@ _public_ sd_bus_creds *sd_bus_creds_unref(sd_bus_creds *c) {
free(c->unique_name);
free(c->cgroup_root);
free(c->description);
free(c->supplementary_gids);
free(c);
}
} else {

View File

@ -677,21 +677,10 @@ static int bus_kernel_make_message(sd_bus *bus, struct kdbus_msg *k) {
case KDBUS_ITEM_AUXGROUPS:
if (bus->creds_mask & SD_BUS_CREDS_SUPPLEMENTARY_GIDS) {
size_t i, n;
uid_t *u;
n = (d->size - offsetof(struct kdbus_item, data32)) / sizeof(uint32_t);
u = new(uid_t, n);
if (!u) {
r = -ENOMEM;
goto fail;
}
for (i = 0; i < n; i++)
u[i] = (uid_t) d->data32[i];
m->creds.supplementary_gids = u;
m->creds.n_supplementary_gids = n;
assert_cc(sizeof(gid_t) == sizeof(uint32_t));
m->creds.n_supplementary_gids = (d->size - offsetof(struct kdbus_item, data32)) / sizeof(uint32_t);
m->creds.supplementary_gids = (gid_t*) d->data32;
m->creds.mask |= SD_BUS_CREDS_SUPPLEMENTARY_GIDS;
}