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:
parent
8514b67754
commit
e12d81ae80
@ -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;
|
||||
|
@ -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 {
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user