chiark / gitweb /
bus: add kdbus endpoint types
authorDaniel Mack <zonque@gmail.com>
Mon, 18 Aug 2014 17:55:32 +0000 (19:55 +0200)
committerDaniel Mack <daniel@zonque.org>
Mon, 8 Sep 2014 09:06:45 +0000 (11:06 +0200)
Add types to describe endpoints and associated policy entries,
and add a BusEndpoint instace to ExecContext.

Makefile.am
src/core/bus-endpoint.c [new file with mode: 0644]
src/core/bus-endpoint.h [new file with mode: 0644]
src/core/execute.c
src/core/execute.h

index 68a78963c19ea7cfc6ae315076d57b988d85544a..35c877fe2a798b426c22634bbb499ec9e4fe422d 100644 (file)
@@ -1028,6 +1028,8 @@ libsystemd_core_la_SOURCES = \
        src/core/busname.h \
        src/core/bus-common.c \
        src/core/bus-common.h \
        src/core/busname.h \
        src/core/bus-common.c \
        src/core/bus-common.h \
+       src/core/bus-endpoint.c \
+       src/core/bus-endpoint.h \
        src/core/target.c \
        src/core/target.h \
        src/core/snapshot.c \
        src/core/target.c \
        src/core/target.h \
        src/core/snapshot.c \
diff --git a/src/core/bus-endpoint.c b/src/core/bus-endpoint.c
new file mode 100644 (file)
index 0000000..8d11974
--- /dev/null
@@ -0,0 +1,90 @@
+/***
+  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 <stdlib.h>
+
+#include "bus-endpoint.h"
+
+int bus_endpoint_new(BusEndpoint **ep)
+{
+        assert(ep);
+
+        *ep = new0(BusEndpoint, 1);
+        if (!*ep)
+                return -ENOMEM;
+
+        return 0;
+}
+
+int bus_endpoint_add_policy(BusEndpoint *ep, const char *name, BusPolicyAccess access)
+{
+        _cleanup_free_ BusEndpointPolicy *po;
+        _cleanup_free_ char *key;
+        int r;
+
+        assert(ep);
+        assert(name);
+        assert(access > _BUS_POLICY_ACCESS_INVALID && access < _BUS_POLICY_ACCESS_MAX);
+
+        /* check if we already have this name in the policy list. If we do, see if the new access level
+         * is higher than the exising one, and upgrade the entry in that case. Otherwise, do nothing.
+         */
+
+        if (ep->policy_hash) {
+                po = hashmap_get(ep->policy_hash, name);
+                if (po) {
+                        if (po->access < access)
+                                po->access = access;
+
+                        return 0;
+                }
+        } else {
+                ep->policy_hash = hashmap_new(string_hash_func, string_compare_func);
+                if (!ep->policy_hash)
+                        return -ENOMEM;
+        }
+
+        po = new0(BusEndpointPolicy, 1);
+        if (!po)
+                return -ENOMEM;
+
+        key = strdup(name);
+        if (!key)
+                return -ENOMEM;
+
+        po->name = key;
+        po->access = access;
+
+        r = hashmap_put(ep->policy_hash, key, po);
+        if (r < 0)
+                return r;
+
+        po = NULL;
+        key = NULL;
+        return 0;
+}
+
+void bus_endpoint_free(BusEndpoint *endpoint)
+{
+        if (!endpoint)
+                return;
+
+        hashmap_free_free_free(endpoint->policy_hash);
+        free(endpoint);
+}
diff --git a/src/core/bus-endpoint.h b/src/core/bus-endpoint.h
new file mode 100644 (file)
index 0000000..2c5415f
--- /dev/null
@@ -0,0 +1,42 @@
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
+
+#pragma once
+
+/***
+  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 struct BusEndpoint BusEndpoint;
+typedef struct BusEndpointPolicy BusEndpointPolicy;
+
+#include "bus-common.h"
+#include "hashmap.h"
+
+struct BusEndpointPolicy {
+        char *name;
+        BusPolicyAccess access;
+};
+
+struct BusEndpoint {
+        Hashmap *policy_hash;
+};
+
+int bus_endpoint_new(BusEndpoint **ep);
+void bus_endpoint_free(BusEndpoint *endpoint);
+
+int bus_endpoint_add_policy(BusEndpoint *ep, const char *name, BusPolicyAccess access);
index 0a5914759f2fae63e510bf6db3a8894293660937..a88e1b19533cce2435e98253a6b557218e1ae37d 100644 (file)
@@ -1908,6 +1908,9 @@ void exec_context_done(ExecContext *c) {
 
         strv_free(c->runtime_directory);
         c->runtime_directory = NULL;
 
         strv_free(c->runtime_directory);
         c->runtime_directory = NULL;
+
+        bus_endpoint_free(c->bus_endpoint);
+        c->bus_endpoint = NULL;
 }
 
 int exec_context_destroy_runtime_directory(ExecContext *c, const char *runtime_prefix) {
 }
 
 int exec_context_destroy_runtime_directory(ExecContext *c, const char *runtime_prefix) {
index f31f0c9f27efba8eb9f5f1dd7ed7a73be6397e20..e3cebfd72cac165d7e0f1b0453b0473fe147fe6f 100644 (file)
@@ -41,6 +41,7 @@ typedef struct ExecParameters ExecParameters;
 #include "fdset.h"
 #include "missing.h"
 #include "namespace.h"
 #include "fdset.h"
 #include "missing.h"
 #include "namespace.h"
+#include "bus-endpoint.h"
 
 typedef enum ExecInput {
         EXEC_INPUT_NULL,
 
 typedef enum ExecInput {
         EXEC_INPUT_NULL,
@@ -188,6 +189,9 @@ struct ExecContext {
         bool ioprio_set:1;
         bool cpu_sched_set:1;
         bool no_new_privileges_set:1;
         bool ioprio_set:1;
         bool cpu_sched_set:1;
         bool no_new_privileges_set:1;
+
+        /* custom dbus enpoint */
+        BusEndpoint *bus_endpoint;
 };
 
 #include "cgroup.h"
 };
 
 #include "cgroup.h"