2003-04-12 Havoc Pennington <hp@pobox.com>
[platform/upstream/dbus.git] / bus / policy.h
1 /* -*- mode: C; c-file-style: "gnu" -*- */
2 /* policy.h  Bus security policy
3  *
4  * Copyright (C) 2003  Red Hat, Inc.
5  *
6  * Licensed under the Academic Free License version 1.2
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 #include <dbus/dbus-string.h>
29 #include "bus.h"
30
31 typedef enum
32 {
33   BUS_POLICY_RULE_SEND,
34   BUS_POLICY_RULE_RECEIVE,
35   BUS_POLICY_RULE_OWN,
36   BUS_POLICY_RULE_USER,
37   BUS_POLICY_RULE_GROUP
38 } BusPolicyRuleType;
39
40 struct BusPolicyRule
41 {
42   int refcount;
43   
44   BusPolicyRuleType type;
45
46   unsigned int allow : 1; /**< #TRUE if this allows, #FALSE if it denies */
47   
48   union
49   {
50     struct
51     {
52       /* either can be NULL meaning "any" */
53       char *message_name;
54       char *destination;
55     } send;
56
57     struct
58     {
59       /* either can be NULL meaning "any" */
60       char *message_name;
61       char *origin;
62     } receive;
63
64     struct
65     {
66       /* can be NULL meaning "any" */
67       char *service_name;
68     } own;
69
70     struct
71     {
72       char *user;
73       unsigned long uid;
74     } user;
75
76     struct
77     {
78       char *group;
79       unsigned long gid;
80     } group;
81     
82   } d;
83 };
84
85 BusPolicyRule* bus_policy_rule_new   (BusPolicyRuleType type,
86                                       dbus_bool_t       allow);
87 void           bus_policy_rule_ref   (BusPolicyRule    *rule);
88 void           bus_policy_rule_unref (BusPolicyRule    *rule);
89
90 BusPolicy*       bus_policy_new                  (void);
91 void             bus_policy_ref                  (BusPolicy      *policy);
92 void             bus_policy_unref                (BusPolicy      *policy);
93 BusClientPolicy* bus_policy_create_client_policy (BusPolicy      *policy,
94                                                   DBusConnection *connection);
95 dbus_bool_t      bus_policy_allow_user           (BusPolicy      *policy,
96                                                   unsigned long   uid);
97
98 BusClientPolicy* bus_client_policy_new               (void);
99 void             bus_client_policy_ref               (BusClientPolicy  *policy);
100 void             bus_client_policy_unref             (BusClientPolicy  *policy);
101 dbus_bool_t      bus_client_policy_check_can_send    (BusClientPolicy  *policy,
102                                                       BusRegistry      *registry,
103                                                       DBusConnection   *receiver,
104                                                       DBusMessage      *message);
105 dbus_bool_t      bus_client_policy_check_can_receive (BusClientPolicy  *policy,
106                                                       BusRegistry      *registry,
107                                                       DBusConnection   *sender,
108                                                       DBusMessage      *message);
109 dbus_bool_t      bus_client_policy_check_can_own     (BusClientPolicy  *policy,
110                                                       DBusConnection   *connection,
111                                                       const DBusString *service_name);
112 dbus_bool_t      bus_client_policy_append_rule       (BusClientPolicy  *policy,
113                                                       BusPolicyRule    *rule);
114 void             bus_client_policy_optimize          (BusClientPolicy  *policy);
115
116
117 #endif /* BUS_POLICY_H */