1
0
mirror of https://github.com/systemd/systemd.git synced 2024-11-02 10:51:20 +03:00

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; uint64_t m;
int r; int r;
assert(bus);
assert(info);
assert(c);
KDBUS_ITEM_FOREACH(item, info, items) { KDBUS_ITEM_FOREACH(item, info, items) {
switch (item->type) { switch (item->type) {
@ -590,18 +594,18 @@ static int bus_populate_creds_from_items(
case KDBUS_ITEM_AUXGROUPS: case KDBUS_ITEM_AUXGROUPS:
if (mask & SD_BUS_CREDS_SUPPLEMENTARY_GIDS) { if (mask & SD_BUS_CREDS_SUPPLEMENTARY_GIDS) {
size_t i, n; size_t n;
uid_t *u; uid_t *g;
n = (item->size - offsetof(struct kdbus_item, data64)) / sizeof(uint64_t); assert_cc(sizeof(gid_t) == sizeof(uint32_t));
u = new(uid_t, n);
if (!u) n = (item->size - offsetof(struct kdbus_item, data32)) / sizeof(uint32_t);
g = newdup(gid_t, item->data32, n);
if (!g)
return -ENOMEM; return -ENOMEM;
for (i = 0; i < n; i++) free(c->supplementary_gids);
u[i] = (uid_t) item->data64[i]; c->supplementary_gids = g;
c->supplementary_gids = u;
c->n_supplementary_gids = n; c->n_supplementary_gids = n;
c->mask |= SD_BUS_CREDS_SUPPLEMENTARY_GIDS; 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->cmdline_array);
strv_free(c->well_known_names); strv_free(c->well_known_names);
free(c->supplementary_gids);
} }
_public_ sd_bus_creds *sd_bus_creds_ref(sd_bus_creds *c) { _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->unique_name);
free(c->cgroup_root); free(c->cgroup_root);
free(c->description); free(c->description);
free(c->supplementary_gids);
free(c); free(c);
} }
} else { } else {

View File

@ -677,21 +677,10 @@ static int bus_kernel_make_message(sd_bus *bus, struct kdbus_msg *k) {
case KDBUS_ITEM_AUXGROUPS: case KDBUS_ITEM_AUXGROUPS:
if (bus->creds_mask & SD_BUS_CREDS_SUPPLEMENTARY_GIDS) { if (bus->creds_mask & SD_BUS_CREDS_SUPPLEMENTARY_GIDS) {
size_t i, n; assert_cc(sizeof(gid_t) == sizeof(uint32_t));
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;
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; m->creds.mask |= SD_BUS_CREDS_SUPPLEMENTARY_GIDS;
} }