*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
+#include <config.h>
#include "policy.h"
#include "services.h"
#include "test.h"
policy->refcount = 1;
- policy->rules_by_uid = _dbus_hash_table_new (DBUS_HASH_ULONG,
+ policy->rules_by_uid = _dbus_hash_table_new (DBUS_HASH_UINTPTR,
NULL,
free_rule_list_func);
if (policy->rules_by_uid == NULL)
goto failed;
- policy->rules_by_gid = _dbus_hash_table_new (DBUS_HASH_ULONG,
+ policy->rules_by_gid = _dbus_hash_table_new (DBUS_HASH_UINTPTR,
NULL,
free_rule_list_func);
if (policy->rules_by_gid == NULL)
{
DBusList **list;
- list = _dbus_hash_table_lookup_ulong (policy->rules_by_gid,
+ list = _dbus_hash_table_lookup_uintptr (policy->rules_by_gid,
groups[i]);
if (list != NULL)
{
DBusList **list;
- list = _dbus_hash_table_lookup_ulong (policy->rules_by_uid,
+ list = _dbus_hash_table_lookup_uintptr (policy->rules_by_uid,
uid);
if (list != NULL)
}
else if (rule->type == BUS_POLICY_RULE_GROUP)
{
- _dbus_verbose ("List %p group rule uid="DBUS_UID_FORMAT"\n",
- list, rule->d.user.uid);
+ _dbus_verbose ("List %p group rule gid="DBUS_GID_FORMAT"\n",
+ list, rule->d.group.gid);
if (rule->d.group.gid == DBUS_GID_UNSET)
; /* '*' wildcard */
{
DBusList **list;
- list = _dbus_hash_table_lookup_ulong (hash, key);
+ list = _dbus_hash_table_lookup_uintptr (hash, key);
if (list == NULL)
{
if (list == NULL)
return NULL;
- if (!_dbus_hash_table_insert_ulong (hash, key, list))
+ if (!_dbus_hash_table_insert_uintptr (hash, key, list))
{
dbus_free (list);
return NULL;
_dbus_hash_iter_init (to_absorb, &iter);
while (_dbus_hash_iter_next (&iter))
{
- unsigned long id = _dbus_hash_iter_get_ulong_key (&iter);
+ unsigned long id = _dbus_hash_iter_get_uintptr_key (&iter);
DBusList **list = _dbus_hash_iter_get_value (&iter);
DBusList **target = get_list (dest, id);
dbus_bool_t requested_reply,
DBusConnection *receiver,
DBusMessage *message,
- dbus_int32_t *toggles)
+ dbus_int32_t *toggles,
+ dbus_bool_t *log)
{
DBusList *link;
dbus_bool_t allowed;
/* Use this rule */
allowed = rule->allow;
+ *log = rule->d.send.log;
(*toggles)++;
_dbus_verbose (" (policy) used rule, allow now = %d\n",
return allowed;
}
-dbus_bool_t
-bus_client_policy_check_can_own (BusClientPolicy *policy,
- DBusConnection *connection,
- const DBusString *service_name)
+
+
+static dbus_bool_t
+bus_rules_check_can_own (DBusList *rules,
+ const DBusString *service_name)
{
DBusList *link;
dbus_bool_t allowed;
- /* policy->rules is in the order the rules appeared
+ /* rules is in the order the rules appeared
* in the config file, i.e. last rule that applies wins
*/
allowed = FALSE;
- link = _dbus_list_get_first_link (&policy->rules);
+ link = _dbus_list_get_first_link (&rules);
while (link != NULL)
{
BusPolicyRule *rule = link->data;
- link = _dbus_list_get_next_link (&policy->rules, link);
+ link = _dbus_list_get_next_link (&rules, link);
/* Rule is skipped if it specifies a different service name from
* the desired one.
if (rule->type != BUS_POLICY_RULE_OWN)
continue;
- if (rule->d.own.service_name != NULL)
+ if (!rule->d.own.prefix && rule->d.own.service_name != NULL)
{
if (!_dbus_string_equal_c_str (service_name,
rule->d.own.service_name))
continue;
}
+ else if (rule->d.own.prefix)
+ {
+ const char *data;
+ char next_char;
+ if (!_dbus_string_starts_with_c_str (service_name,
+ rule->d.own.service_name))
+ continue;
+
+ data = _dbus_string_get_const_data (service_name);
+ next_char = data[strlen (rule->d.own.service_name)];
+ if (next_char != '\0' && next_char != '.')
+ continue;
+ }
/* Use this rule */
allowed = rule->allow;
return allowed;
}
-#ifdef DBUS_BUILD_TESTS
+dbus_bool_t
+bus_client_policy_check_can_own (BusClientPolicy *policy,
+ const DBusString *service_name)
+{
+ return bus_rules_check_can_own (policy->rules, service_name);
+}
+#ifdef DBUS_ENABLE_EMBEDDED_TESTS
dbus_bool_t
-bus_policy_test (const DBusString *test_data_dir)
+bus_policy_check_can_own (BusPolicy *policy,
+ const DBusString *service_name)
{
- /* This doesn't do anything for now because I decided to do it in
- * dispatch.c instead by having some of the clients in dispatch.c
- * have particular policies applied to them.
- */
-
- return TRUE;
+ return bus_rules_check_can_own (policy->default_rules, service_name);
}
+#endif /* DBUS_ENABLE_EMBEDDED_TESTS */
-#endif /* DBUS_BUILD_TESTS */