summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
Diffstat (limited to 'src/core')
-rw-r--r--src/core/bus-common.c35
-rw-r--r--src/core/bus-common.h35
-rw-r--r--src/core/bus-endpoint.c56
-rw-r--r--src/core/bus-endpoint.h4
-rw-r--r--src/core/busname.c3
-rw-r--r--src/core/busname.h17
-rw-r--r--src/core/execute.c2
7 files changed, 56 insertions, 96 deletions
diff --git a/src/core/bus-common.c b/src/core/bus-common.c
deleted file mode 100644
index 4a61cb9a3a..0000000000
--- a/src/core/bus-common.c
+++ /dev/null
@@ -1,35 +0,0 @@
-/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
-
-/***
- This file is part of systemd.
-
- Copyright 2014 Daniel Mack
-
- systemd is free software; you can redistribute it and/or modify it
- under the terms of the GNU Lesser General Public License as published by
- the Free Software Foundation; either version 2.1 of the License, or
- (at your option) any later version.
-
- systemd is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public License
- along with systemd; If not, see <http://www.gnu.org/licenses/>.
-***/
-
-#include "special.h"
-#include "bus-kernel.h"
-#include "bus-internal.h"
-#include "bus-util.h"
-#include "service.h"
-#include "bus-common.h"
-
-static const char* const bus_policy_access_table[_BUS_POLICY_ACCESS_MAX] = {
- [BUS_POLICY_ACCESS_SEE] = "see",
- [BUS_POLICY_ACCESS_TALK] = "talk",
- [BUS_POLICY_ACCESS_OWN] = "own",
-};
-
-DEFINE_STRING_TABLE_LOOKUP(bus_policy_access, BusPolicyAccess);
diff --git a/src/core/bus-common.h b/src/core/bus-common.h
deleted file mode 100644
index 209f870c72..0000000000
--- a/src/core/bus-common.h
+++ /dev/null
@@ -1,35 +0,0 @@
-/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
-
-#pragma once
-
-#include "macro.h"
-
-/***
- This file is part of systemd.
-
- Copyright 2014 Daniel Mack
-
- systemd is free software; you can redistribute it and/or modify it
- under the terms of the GNU Lesser General Public License as published by
- the Free Software Foundation; either version 2.1 of the License, or
- (at your option) any later version.
-
- systemd is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public License
- along with systemd; If not, see <http://www.gnu.org/licenses/>.
-***/
-
-typedef enum BusPolicyAccess {
- BUS_POLICY_ACCESS_SEE,
- BUS_POLICY_ACCESS_TALK,
- BUS_POLICY_ACCESS_OWN,
- _BUS_POLICY_ACCESS_MAX,
- _BUS_POLICY_ACCESS_INVALID = -1
-} BusPolicyAccess;
-
-const char* bus_policy_access_to_string(BusPolicyAccess i) _const_;
-BusPolicyAccess bus_policy_access_from_string(const char *s) _pure_;
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;
diff --git a/src/core/bus-endpoint.h b/src/core/bus-endpoint.h
index 2c5415f34e..4a31f4c4be 100644
--- a/src/core/bus-endpoint.h
+++ b/src/core/bus-endpoint.h
@@ -24,8 +24,8 @@
typedef struct BusEndpoint BusEndpoint;
typedef struct BusEndpointPolicy BusEndpointPolicy;
-#include "bus-common.h"
#include "hashmap.h"
+#include "bus-policy.h"
struct BusEndpointPolicy {
char *name;
@@ -40,3 +40,5 @@ int bus_endpoint_new(BusEndpoint **ep);
void bus_endpoint_free(BusEndpoint *endpoint);
int bus_endpoint_add_policy(BusEndpoint *ep, const char *name, BusPolicyAccess access);
+
+int bus_kernel_set_endpoint_policy(int fd, uid_t uid, BusEndpoint *ep);
diff --git a/src/core/busname.c b/src/core/busname.c
index acd665282d..9ab95569eb 100644
--- a/src/core/busname.c
+++ b/src/core/busname.c
@@ -26,9 +26,10 @@
#include "bus-internal.h"
#include "bus-util.h"
#include "service.h"
+#include "kdbus.h"
+#include "bus-policy.h"
#include "dbus-busname.h"
#include "busname.h"
-#include "kdbus.h"
static const UnitActiveState state_translation_table[_BUSNAME_STATE_MAX] = {
[BUSNAME_DEAD] = UNIT_INACTIVE,
diff --git a/src/core/busname.h b/src/core/busname.h
index c9b653d82e..775822d8de 100644
--- a/src/core/busname.h
+++ b/src/core/busname.h
@@ -25,7 +25,6 @@ typedef struct BusName BusName;
typedef struct BusNamePolicy BusNamePolicy;
#include "unit.h"
-#include "bus-common.h"
typedef enum BusNameState {
BUSNAME_DEAD,
@@ -52,22 +51,6 @@ typedef enum BusNameResult {
_BUSNAME_RESULT_INVALID = -1
} BusNameResult;
-typedef enum BusNamePolicyType {
- BUSNAME_POLICY_TYPE_USER,
- BUSNAME_POLICY_TYPE_GROUP,
- _BUSNAME_POLICY_TYPE_MAX,
- _BUSNAME_POLICY_TYPE_INVALID = -1
-} BusNamePolicyType;
-
-struct BusNamePolicy {
- BusNamePolicyType type;
- BusPolicyAccess access;
-
- char *name;
-
- LIST_FIELDS(BusNamePolicy, policy);
-};
-
struct BusName {
Unit meta;
diff --git a/src/core/execute.c b/src/core/execute.c
index 4735ab2417..c472dadfed 100644
--- a/src/core/execute.c
+++ b/src/core/execute.c
@@ -84,7 +84,7 @@
#include "mkdir.h"
#include "apparmor-util.h"
#include "smack-util.h"
-#include "bus-kernel.h"
+#include "bus-endpoint.h"
#include "label.h"
#include "cap-list.h"