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!
This commit is contained in:
Lennart Poettering
2014-12-23 19:15:27 +01:00
parent 3e0a204897
commit 3c70e3bb02
17 changed files with 74 additions and 302 deletions
-35
View File
@@ -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);
-35
View File
@@ -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_;
+50 -6
View File
@@ -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;
+3 -1
View File
@@ -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);
+2 -1
View File
@@ -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,
-17
View File
@@ -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;
+1 -1
View File
@@ -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"