diff options
author | Lennart Poettering <lennart@poettering.net> | 2014-12-23 18:36:04 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2014-12-23 19:15:27 +0100 |
commit | 3c70e3bb022f0de3317f3600c9366a2f4597339e (patch) | |
tree | f8cd5021f6f4bc2dd8fe8b6d777ca85d9f6fb896 /src/core/bus-endpoint.c | |
parent | 3e0a2048978fcc7aff00797bdb876b2592c2fbc7 (diff) |
core: rearrange code so that libsystemd/sd-bus/ does not include header files from core
Stuff in src/shared or src/libsystemd should *never* include code from
src/core or any of the tools, so don't do that here either. It's not OK!
Diffstat (limited to 'src/core/bus-endpoint.c')
-rw-r--r-- | src/core/bus-endpoint.c | 56 |
1 files changed, 50 insertions, 6 deletions
diff --git a/src/core/bus-endpoint.c b/src/core/bus-endpoint.c index aac540ddee..27dd192a2f 100644 --- a/src/core/bus-endpoint.c +++ b/src/core/bus-endpoint.c @@ -19,10 +19,56 @@ #include <stdlib.h> +#include "kdbus.h" +#include "bus-kernel.h" +#include "bus-policy.h" #include "bus-endpoint.h" -int bus_endpoint_new(BusEndpoint **ep) -{ +int bus_kernel_set_endpoint_policy(int fd, uid_t uid, BusEndpoint *ep) { + + struct kdbus_cmd_update *update; + struct kdbus_item *n; + BusEndpointPolicy *po; + Iterator i; + size_t size; + int r; + + size = ALIGN8(offsetof(struct kdbus_cmd_update, items)); + + HASHMAP_FOREACH(po, ep->policy_hash, i) { + size += ALIGN8(offsetof(struct kdbus_item, str) + strlen(po->name) + 1); + size += ALIGN8(offsetof(struct kdbus_item, policy_access) + sizeof(struct kdbus_policy_access)); + } + + update = alloca0_align(size, 8); + update->size = size; + + n = update->items; + + HASHMAP_FOREACH(po, ep->policy_hash, i) { + n->type = KDBUS_ITEM_NAME; + n->size = offsetof(struct kdbus_item, str) + strlen(po->name) + 1; + strcpy(n->str, po->name); + n = KDBUS_ITEM_NEXT(n); + + n->type = KDBUS_ITEM_POLICY_ACCESS; + n->size = offsetof(struct kdbus_item, policy_access) + sizeof(struct kdbus_policy_access); + + n->policy_access.type = KDBUS_POLICY_ACCESS_USER; + n->policy_access.access = bus_kernel_translate_access(po->access); + n->policy_access.id = uid; + + n = KDBUS_ITEM_NEXT(n); + } + + r = ioctl(fd, KDBUS_CMD_ENDPOINT_UPDATE, update); + if (r < 0) + return -errno; + + return 0; +} + +int bus_endpoint_new(BusEndpoint **ep) { assert(ep); *ep = new0(BusEndpoint, 1); @@ -32,8 +78,7 @@ int bus_endpoint_new(BusEndpoint **ep) return 0; } -int bus_endpoint_add_policy(BusEndpoint *ep, const char *name, BusPolicyAccess access) -{ +int bus_endpoint_add_policy(BusEndpoint *ep, const char *name, BusPolicyAccess access) { _cleanup_free_ BusEndpointPolicy *po = NULL; _cleanup_free_ char *key = NULL; int r; @@ -80,8 +125,7 @@ int bus_endpoint_add_policy(BusEndpoint *ep, const char *name, BusPolicyAccess a return 0; } -void bus_endpoint_free(BusEndpoint *endpoint) -{ +void bus_endpoint_free(BusEndpoint *endpoint) { if (!endpoint) return; |