|
1 /* -*- mode: C; c-file-style: "gnu" -*- */ |
|
2 /* policy.h Bus security policy |
|
3 * |
|
4 * Copyright (C) 2003 Red Hat, Inc. |
|
5 * Portion Copyright © 2008 Nokia Corporation and/or its subsidiary(-ies). All rights reserved. |
|
6 * Licensed under the Academic Free License version 2.1 |
|
7 * |
|
8 * This program is free software; you can redistribute it and/or modify |
|
9 * it under the terms of the GNU General Public License as published by |
|
10 * the Free Software Foundation; either version 2 of the License, or |
|
11 * (at your option) any later version. |
|
12 * |
|
13 * This program is distributed in the hope that it will be useful, |
|
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
16 * GNU General Public License for more details. |
|
17 * |
|
18 * You should have received a copy of the GNU General Public License |
|
19 * along with this program; if not, write to the Free Software |
|
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
21 * |
|
22 */ |
|
23 |
|
24 #ifndef BUS_POLICY_H |
|
25 #define BUS_POLICY_H |
|
26 |
|
27 #include <dbus/dbus.h> |
|
28 #ifndef __SYMBIAN32__ |
|
29 #include <dbus/dbus-string.h> |
|
30 #include <dbus/dbus-list.h> |
|
31 #include <dbus/dbus-sysdeps.h> |
|
32 #else |
|
33 #include "dbus-string.h" |
|
34 #include "dbus-list.h" |
|
35 #include "dbus-sysdeps.h" |
|
36 #endif //__SYMBIAN32__ |
|
37 #include "bus.h" |
|
38 |
|
39 typedef enum |
|
40 { |
|
41 BUS_POLICY_RULE_SEND, |
|
42 BUS_POLICY_RULE_RECEIVE, |
|
43 BUS_POLICY_RULE_OWN, |
|
44 BUS_POLICY_RULE_USER, |
|
45 BUS_POLICY_RULE_GROUP |
|
46 } BusPolicyRuleType; |
|
47 |
|
48 /** determines whether the rule affects a connection, or some global item */ |
|
49 #define BUS_POLICY_RULE_IS_PER_CLIENT(rule) (!((rule)->type == BUS_POLICY_RULE_USER || \ |
|
50 (rule)->type == BUS_POLICY_RULE_GROUP)) |
|
51 |
|
52 struct BusPolicyRule |
|
53 { |
|
54 int refcount; |
|
55 |
|
56 BusPolicyRuleType type; |
|
57 |
|
58 unsigned int allow : 1; /**< #TRUE if this allows, #FALSE if it denies */ |
|
59 |
|
60 union |
|
61 { |
|
62 struct |
|
63 { |
|
64 /* message type can be DBUS_MESSAGE_TYPE_INVALID meaning "any" */ |
|
65 int message_type; |
|
66 /* any of these can be NULL meaning "any" */ |
|
67 char *path; |
|
68 char *interface; |
|
69 char *member; |
|
70 char *error; |
|
71 char *destination; |
|
72 unsigned int requested_reply : 1; |
|
73 } send; |
|
74 |
|
75 struct |
|
76 { |
|
77 /* message type can be DBUS_MESSAGE_TYPE_INVALID meaning "any" */ |
|
78 int message_type; |
|
79 /* any of these can be NULL meaning "any" */ |
|
80 char *path; |
|
81 char *interface; |
|
82 char *member; |
|
83 char *error; |
|
84 char *origin; |
|
85 unsigned int eavesdrop : 1; |
|
86 unsigned int requested_reply : 1; |
|
87 } receive; |
|
88 |
|
89 struct |
|
90 { |
|
91 /* can be NULL meaning "any" */ |
|
92 char *service_name; |
|
93 } own; |
|
94 |
|
95 struct |
|
96 { |
|
97 /* can be DBUS_UID_UNSET meaning "any" */ |
|
98 dbus_uid_t uid; |
|
99 } user; |
|
100 |
|
101 struct |
|
102 { |
|
103 /* can be DBUS_GID_UNSET meaning "any" */ |
|
104 dbus_gid_t gid; |
|
105 } group; |
|
106 |
|
107 } d; |
|
108 }; |
|
109 |
|
110 BusPolicyRule* bus_policy_rule_new (BusPolicyRuleType type, |
|
111 dbus_bool_t allow); |
|
112 BusPolicyRule* bus_policy_rule_ref (BusPolicyRule *rule); |
|
113 void bus_policy_rule_unref (BusPolicyRule *rule); |
|
114 |
|
115 BusPolicy* bus_policy_new (void); |
|
116 BusPolicy* bus_policy_ref (BusPolicy *policy); |
|
117 void bus_policy_unref (BusPolicy *policy); |
|
118 BusClientPolicy* bus_policy_create_client_policy (BusPolicy *policy, |
|
119 DBusConnection *connection, |
|
120 DBusError *error); |
|
121 dbus_bool_t bus_policy_allow_user (BusPolicy *policy, |
|
122 DBusUserDatabase *user_database, |
|
123 unsigned long uid); |
|
124 dbus_bool_t bus_policy_append_default_rule (BusPolicy *policy, |
|
125 BusPolicyRule *rule); |
|
126 dbus_bool_t bus_policy_append_mandatory_rule (BusPolicy *policy, |
|
127 BusPolicyRule *rule); |
|
128 dbus_bool_t bus_policy_append_user_rule (BusPolicy *policy, |
|
129 dbus_uid_t uid, |
|
130 BusPolicyRule *rule); |
|
131 dbus_bool_t bus_policy_append_group_rule (BusPolicy *policy, |
|
132 dbus_gid_t gid, |
|
133 BusPolicyRule *rule); |
|
134 dbus_bool_t bus_policy_append_console_rule (BusPolicy *policy, |
|
135 dbus_bool_t at_console, |
|
136 BusPolicyRule *rule); |
|
137 |
|
138 dbus_bool_t bus_policy_merge (BusPolicy *policy, |
|
139 BusPolicy *to_absorb); |
|
140 |
|
141 BusClientPolicy* bus_client_policy_new (void); |
|
142 BusClientPolicy* bus_client_policy_ref (BusClientPolicy *policy); |
|
143 void bus_client_policy_unref (BusClientPolicy *policy); |
|
144 dbus_bool_t bus_client_policy_check_can_send (BusClientPolicy *policy, |
|
145 BusRegistry *registry, |
|
146 dbus_bool_t requested_reply, |
|
147 DBusConnection *receiver, |
|
148 DBusMessage *message); |
|
149 dbus_bool_t bus_client_policy_check_can_receive (BusClientPolicy *policy, |
|
150 BusRegistry *registry, |
|
151 dbus_bool_t requested_reply, |
|
152 DBusConnection *sender, |
|
153 DBusConnection *addressed_recipient, |
|
154 DBusConnection *proposed_recipient, |
|
155 DBusMessage *message); |
|
156 dbus_bool_t bus_client_policy_check_can_own (BusClientPolicy *policy, |
|
157 DBusConnection *connection, |
|
158 const DBusString *service_name); |
|
159 dbus_bool_t bus_client_policy_append_rule (BusClientPolicy *policy, |
|
160 BusPolicyRule *rule); |
|
161 void bus_client_policy_optimize (BusClientPolicy *policy); |
|
162 |
|
163 |
|
164 #endif /* BUS_POLICY_H */ |