2003-03-23 Havoc Pennington <hp@pobox.com>
[platform/upstream/dbus.git] / bus / policy.h
1 /* -*- mode: C; c-file-style: "gnu" -*- */
2 /* policy.h  Policies for what a connection can do
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 dbus_bool_t bus_policy_check_can_send    (BusPolicy        *policy,
94                                           BusRegistry      *registry,
95                                           DBusConnection   *receiver,
96                                           DBusMessage      *message);
97 dbus_bool_t bus_policy_check_can_receive (BusPolicy        *policy,
98                                           BusRegistry      *registry,
99                                           DBusConnection   *sender,
100                                           DBusMessage      *message);
101 dbus_bool_t bus_policy_check_can_own     (BusPolicy        *policy,
102                                           DBusConnection   *connection,
103                                           const DBusString *service_name);
104 dbus_bool_t bus_policy_append_rule       (BusPolicy        *policy,
105                                           BusPolicyRule    *rule);
106 void        bus_policy_optimize          (BusPolicy        *policy);
107
108 #endif /* BUS_POLICY_H */