chiark / gitweb /
762cb663a09891c6d07bcdf3372819bf131be856
[elogind.git] / src / bus-proxyd / bus-xml-policy.h
1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2
3 #pragma once
4
5 /***
6   This file is part of systemd.
7
8   Copyright 2013 Lennart Poettering
9
10   systemd is free software; you can redistribute it and/or modify it
11   under the terms of the GNU Lesser General Public License as published by
12   the Free Software Foundation; either version 2.1 of the License, or
13   (at your option) any later version.
14
15   systemd is distributed in the hope that it will be useful, but
16   WITHOUT ANY WARRANTY; without even the implied warranty of
17   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18   Lesser General Public License for more details.
19
20   You should have received a copy of the GNU Lesser General Public License
21   along with systemd; If not, see <http://www.gnu.org/licenses/>.
22 ***/
23
24 #include <inttypes.h>
25 #include <pthread.h>
26
27 #include "list.h"
28 #include "hashmap.h"
29
30 typedef enum PolicyItemType {
31         _POLICY_ITEM_TYPE_UNSET = 0,
32         POLICY_ITEM_ALLOW,
33         POLICY_ITEM_DENY,
34         _POLICY_ITEM_TYPE_MAX,
35         _POLICY_ITEM_TYPE_INVALID = -1,
36 } PolicyItemType;
37
38 typedef enum PolicyItemClass {
39         _POLICY_ITEM_CLASS_UNSET = 0,
40         POLICY_ITEM_SEND,
41         POLICY_ITEM_RECV,
42         POLICY_ITEM_OWN,
43         POLICY_ITEM_OWN_PREFIX,
44         POLICY_ITEM_USER,
45         POLICY_ITEM_GROUP,
46         POLICY_ITEM_IGNORE,
47         _POLICY_ITEM_CLASS_MAX,
48         _POLICY_ITEM_CLASS_INVALID = -1,
49 } PolicyItemClass;
50
51 typedef struct PolicyItem PolicyItem;
52
53 struct PolicyItem {
54         PolicyItemType type;
55         PolicyItemClass class;
56         char *interface;
57         char *member;
58         char *error;
59         char *path;
60         char *name;
61         uint8_t message_type;
62         uid_t uid;
63         gid_t gid;
64
65         bool uid_valid, gid_valid;
66
67         LIST_FIELDS(PolicyItem, items);
68 };
69
70 typedef struct Policy {
71         LIST_HEAD(PolicyItem, default_items);
72         LIST_HEAD(PolicyItem, mandatory_items);
73         LIST_HEAD(PolicyItem, on_console_items);
74         LIST_HEAD(PolicyItem, no_console_items);
75         Hashmap *user_items;
76         Hashmap *group_items;
77 } Policy;
78
79 typedef struct SharedPolicy {
80         pthread_mutex_t lock;
81         pthread_rwlock_t rwlock;
82         Policy buffer;
83         Policy *policy;
84 } SharedPolicy;
85
86 /* policy */
87
88 int policy_load(Policy *p, char **files);
89 void policy_free(Policy *p);
90
91 bool policy_check_own(Policy *p, uid_t uid, gid_t gid, const char *name);
92 bool policy_check_hello(Policy *p, uid_t uid, gid_t gid);
93 bool policy_check_recv(Policy *p,
94                        uid_t uid,
95                        gid_t gid,
96                        int message_type,
97                        const char *name,
98                        const char *path,
99                        const char *interface,
100                        const char *member,
101                        bool dbus_to_kernel);
102 bool policy_check_send(Policy *p,
103                        uid_t uid,
104                        gid_t gid,
105                        int message_type,
106                        const char *name,
107                        const char *path,
108                        const char *interface,
109                        const char *member,
110                        bool dbus_to_kernel);
111
112 void policy_dump(Policy *p);
113
114 const char* policy_item_type_to_string(PolicyItemType t) _const_;
115 PolicyItemType policy_item_type_from_string(const char *s) _pure_;
116
117 const char* policy_item_class_to_string(PolicyItemClass t) _const_;
118 PolicyItemClass policy_item_class_from_string(const char *s) _pure_;
119
120 /* shared policy */
121
122 int shared_policy_new(SharedPolicy **out);
123 SharedPolicy *shared_policy_free(SharedPolicy *sp);
124
125 int shared_policy_reload(SharedPolicy *sp, char **configuration);
126 int shared_policy_preload(SharedPolicy *sp, char **configuration);
127 Policy *shared_policy_acquire(SharedPolicy *sp);
128 void shared_policy_release(SharedPolicy *sp, Policy *p);
129
130 DEFINE_TRIVIAL_CLEANUP_FUNC(SharedPolicy*, shared_policy_free);