chiark / gitweb /
125c84cd6ed73ece62b92e9829e6936362f9a438
[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
26 #include "list.h"
27 #include "hashmap.h"
28
29 typedef enum PolicyItemType {
30         _POLICY_ITEM_TYPE_UNSET = 0,
31         POLICY_ITEM_ALLOW,
32         POLICY_ITEM_DENY,
33         _POLICY_ITEM_TYPE_MAX,
34         _POLICY_ITEM_TYPE_INVALID = -1,
35 } PolicyItemType;
36
37 typedef enum PolicyItemClass {
38         _POLICY_ITEM_CLASS_UNSET = 0,
39         POLICY_ITEM_SEND,
40         POLICY_ITEM_RECV,
41         POLICY_ITEM_OWN,
42         POLICY_ITEM_OWN_PREFIX,
43         POLICY_ITEM_USER,
44         POLICY_ITEM_GROUP,
45         POLICY_ITEM_IGNORE,
46         _POLICY_ITEM_CLASS_MAX,
47         _POLICY_ITEM_CLASS_INVALID = -1,
48 } PolicyItemClass;
49
50 typedef struct PolicyItem PolicyItem;
51
52 struct PolicyItem {
53         PolicyItemType type;
54         PolicyItemClass class;
55         char *interface;
56         char *member;
57         char *error;
58         char *path;
59         char *name;
60         uint8_t message_type;
61         uid_t uid;
62         gid_t gid;
63
64         bool uid_valid, gid_valid;
65
66         LIST_FIELDS(PolicyItem, items);
67 };
68
69 typedef struct Policy {
70         LIST_HEAD(PolicyItem, default_items);
71         LIST_HEAD(PolicyItem, mandatory_items);
72         LIST_HEAD(PolicyItem, on_console_items);
73         LIST_HEAD(PolicyItem, no_console_items);
74         Hashmap *user_items;
75         Hashmap *group_items;
76 } Policy;
77
78 int policy_load(Policy *p, char **files);
79 void policy_free(Policy *p);
80
81 bool policy_check_own(Policy *p, uid_t uid, gid_t gid, const char *name);
82 bool policy_check_hello(Policy *p, uid_t uid, gid_t gid);
83 bool policy_check_recv(Policy *p,
84                        uid_t uid,
85                        gid_t gid,
86                        int message_type,
87                        const char *name,
88                        const char *path,
89                        const char *interface,
90                        const char *member,
91                        bool dbus_to_kernel);
92 bool policy_check_send(Policy *p,
93                        uid_t uid,
94                        gid_t gid,
95                        int message_type,
96                        const char *name,
97                        const char *path,
98                        const char *interface,
99                        const char *member,
100                        bool dbus_to_kernel);
101
102 void policy_dump(Policy *p);
103
104 const char* policy_item_type_to_string(PolicyItemType t) _const_;
105 PolicyItemType policy_item_type_from_string(const char *s) _pure_;
106
107 const char* policy_item_class_to_string(PolicyItemClass t) _const_;
108 PolicyItemClass policy_item_class_from_string(const char *s) _pure_;