diff options
author | Jacek Bukarewicz <j.bukarewicz@samsung.com> | 2014-11-27 11:26:21 +0100 |
---|---|---|
committer | Jacek Bukarewicz <j.bukarewicz@samsung.com> | 2014-12-12 17:37:43 +0100 |
commit | ae96d3c95d040c7d95c9a09e738d472db7228fdc (patch) | |
tree | 935c362e0d069504ab3bcad9cc1730481fb31b75 | |
parent | 2db663cda78bc43c22b1313fc8c5896d1115ef62 (diff) | |
download | dbus-ae96d3c95d040c7d95c9a09e738d472db7228fdc.tar.gz dbus-ae96d3c95d040c7d95c9a09e738d472db7228fdc.tar.bz2 dbus-ae96d3c95d040c7d95c9a09e738d472db7228fdc.zip |
Add <check own="..." > support
Policy result unavailability is handled like send rules - dispatching
messages from the sender is blocked and resumed when result becomes
available.
Handler of "RequestName" method needs to return BUS_RESULT_LATER when
policy result is not known therefore its return type is modified.
Since bus message handlers are put into function pointer array other
message handler function singatures are also affected.
Change-Id: I4c2cbd4585e41fccd8a30f825a8f0d342ab56755
-rw-r--r-- | bus/dispatch.c | 14 | ||||
-rw-r--r-- | bus/driver.c | 229 | ||||
-rw-r--r-- | bus/driver.h | 2 | ||||
-rw-r--r-- | bus/policy.c | 51 | ||||
-rw-r--r-- | bus/policy.h | 6 | ||||
-rw-r--r-- | bus/services.c | 41 | ||||
-rw-r--r-- | bus/services.h | 3 | ||||
-rw-r--r-- | bus/smack.c | 12 | ||||
-rw-r--r-- | bus/stats.c | 16 |
9 files changed, 218 insertions, 156 deletions
diff --git a/bus/dispatch.c b/bus/dispatch.c index 143ff3fb..4a2dae84 100644 --- a/bus/dispatch.c +++ b/bus/dispatch.c @@ -408,8 +408,18 @@ bus_dispatch (DBusConnection *connection, } _dbus_verbose ("Giving message to %s\n", DBUS_SERVICE_DBUS); - if (!bus_driver_handle_message (connection, transaction, message, &error)) - goto out; + switch (bus_driver_handle_message (connection, transaction, message, &error)) + { + case BUS_RESULT_TRUE: + break; + case BUS_RESULT_FALSE: + goto out; + case BUS_RESULT_LATER: + bus_transaction_cancel_and_free (transaction); + transaction = NULL; + result = DBUS_HANDLER_RESULT_LATER; + goto out; + } } else if (!bus_connection_is_active (connection)) /* clients must talk to bus driver first */ { diff --git a/bus/driver.c b/bus/driver.c index 914c681d..2e6d4729 100644 --- a/bus/driver.c +++ b/bus/driver.c @@ -299,7 +299,7 @@ create_unique_client_name (BusRegistry *registry, return TRUE; } -static dbus_bool_t +static BusResult bus_driver_handle_hello (DBusConnection *connection, BusTransaction *transaction, DBusMessage *message, @@ -307,7 +307,7 @@ bus_driver_handle_hello (DBusConnection *connection, { DBusString unique_name; BusService *service; - dbus_bool_t retval; + BusResult retval; BusRegistry *registry; BusConnections *connections; @@ -318,7 +318,7 @@ bus_driver_handle_hello (DBusConnection *connection, /* We already handled an Hello message for this connection. */ dbus_set_error (error, DBUS_ERROR_FAILED, "Already handled an Hello message"); - return FALSE; + return BUS_RESULT_FALSE; } /* Note that when these limits are exceeded we don't disconnect the @@ -332,13 +332,13 @@ bus_driver_handle_hello (DBusConnection *connection, error)) { _DBUS_ASSERT_ERROR_IS_SET (error); - return FALSE; + return BUS_RESULT_FALSE; } if (!_dbus_string_init (&unique_name)) { BUS_SET_OOM (error); - return FALSE; + return BUS_RESULT_FALSE; } retval = FALSE; @@ -374,7 +374,7 @@ bus_driver_handle_hello (DBusConnection *connection, goto out_0; _dbus_assert (bus_connection_is_active (connection)); - retval = TRUE; + retval = BUS_RESULT_TRUE; out_0: _dbus_string_free (&unique_name); @@ -426,7 +426,7 @@ bus_driver_send_welcome_message (DBusConnection *connection, } } -static dbus_bool_t +static BusResult bus_driver_handle_list_services (DBusConnection *connection, BusTransaction *transaction, DBusMessage *message, @@ -448,14 +448,14 @@ bus_driver_handle_list_services (DBusConnection *connection, if (reply == NULL) { BUS_SET_OOM (error); - return FALSE; + return BUS_RESULT_FALSE; } if (!bus_registry_list_services (registry, &services, &len)) { dbus_message_unref (reply); BUS_SET_OOM (error); - return FALSE; + return BUS_RESULT_FALSE; } dbus_message_iter_init_append (reply, &iter); @@ -467,7 +467,7 @@ bus_driver_handle_list_services (DBusConnection *connection, dbus_free_string_array (services); dbus_message_unref (reply); BUS_SET_OOM (error); - return FALSE; + return BUS_RESULT_FALSE; } { @@ -479,7 +479,7 @@ bus_driver_handle_list_services (DBusConnection *connection, dbus_free_string_array (services); dbus_message_unref (reply); BUS_SET_OOM (error); - return FALSE; + return BUS_RESULT_FALSE; } } @@ -492,7 +492,7 @@ bus_driver_handle_list_services (DBusConnection *connection, dbus_free_string_array (services); dbus_message_unref (reply); BUS_SET_OOM (error); - return FALSE; + return BUS_RESULT_FALSE; } ++i; } @@ -503,23 +503,23 @@ bus_driver_handle_list_services (DBusConnection *connection, { dbus_message_unref (reply); BUS_SET_OOM (error); - return FALSE; + return BUS_RESULT_FALSE; } if (!bus_transaction_send_from_driver (transaction, connection, reply)) { dbus_message_unref (reply); BUS_SET_OOM (error); - return FALSE; + return BUS_RESULT_FALSE; } else { dbus_message_unref (reply); - return TRUE; + return BUS_RESULT_TRUE; } } -static dbus_bool_t +static BusResult bus_driver_handle_list_activatable_services (DBusConnection *connection, BusTransaction *transaction, DBusMessage *message, @@ -541,14 +541,14 @@ bus_driver_handle_list_activatable_services (DBusConnection *connection, if (reply == NULL) { BUS_SET_OOM (error); - return FALSE; + return BUS_RESULT_FALSE; } if (!bus_activation_list_services (activation, &services, &len)) { dbus_message_unref (reply); BUS_SET_OOM (error); - return FALSE; + return BUS_RESULT_FALSE; } dbus_message_iter_init_append (reply, &iter); @@ -560,7 +560,7 @@ bus_driver_handle_list_activatable_services (DBusConnection *connection, dbus_free_string_array (services); dbus_message_unref (reply); BUS_SET_OOM (error); - return FALSE; + return BUS_RESULT_FALSE; } { @@ -572,7 +572,7 @@ bus_driver_handle_list_activatable_services (DBusConnection *connection, dbus_free_string_array (services); dbus_message_unref (reply); BUS_SET_OOM (error); - return FALSE; + return BUS_RESULT_FALSE; } } @@ -585,7 +585,7 @@ bus_driver_handle_list_activatable_services (DBusConnection *connection, dbus_free_string_array (services); dbus_message_unref (reply); BUS_SET_OOM (error); - return FALSE; + return BUS_RESULT_FALSE; } ++i; } @@ -596,23 +596,23 @@ bus_driver_handle_list_activatable_services (DBusConnection *connection, { dbus_message_unref (reply); BUS_SET_OOM (error); - return FALSE; + return BUS_RESULT_FALSE; } if (!bus_transaction_send_from_driver (transaction, connection, reply)) { dbus_message_unref (reply); BUS_SET_OOM (error); - return FALSE; + return BUS_RESULT_FALSE; } else { dbus_message_unref (reply); - return TRUE; + return BUS_RESULT_TRUE; } } -static dbus_bool_t +static BusResult bus_driver_handle_acquire_service (DBusConnection *connection, BusTransaction *transaction, DBusMessage *message, @@ -623,7 +623,7 @@ bus_driver_handle_acquire_service (DBusConnection *connection, const char *name; dbus_uint32_t service_reply; dbus_uint32_t flags; - dbus_bool_t retval; + BusResult retval; BusRegistry *registry; _DBUS_ASSERT_ERROR_IS_CLEAR (error); @@ -634,20 +634,28 @@ bus_driver_handle_acquire_service (DBusConnection *connection, DBUS_TYPE_STRING, &name, DBUS_TYPE_UINT32, &flags, DBUS_TYPE_INVALID)) - return FALSE; + return BUS_RESULT_FALSE; _dbus_verbose ("Trying to own name %s with flags 0x%x\n", name, flags); - retval = FALSE; + retval = BUS_RESULT_FALSE; reply = NULL; _dbus_string_init_const (&service_name, name); - if (!bus_registry_acquire_service (registry, connection, - &service_name, flags, - &service_reply, transaction, - error)) - goto out; + switch (bus_registry_acquire_service (registry, connection, message, + &service_name, flags, + &service_reply, transaction, + error)) + { + case BUS_RESULT_TRUE: + break; + case BUS_RESULT_FALSE: + goto out; + case BUS_RESULT_LATER: + retval = BUS_RESULT_LATER; + goto out; + } reply = dbus_message_new_method_return (message); if (reply == NULL) @@ -668,7 +676,7 @@ bus_driver_handle_acquire_service (DBusConnection *connection, goto out; } - retval = TRUE; + retval = BUS_RESULT_TRUE; out: if (reply) @@ -676,7 +684,7 @@ bus_driver_handle_acquire_service (DBusConnection *connection, return retval; } -static dbus_bool_t +static BusResult bus_driver_handle_release_service (DBusConnection *connection, BusTransaction *transaction, DBusMessage *message, @@ -686,7 +694,7 @@ bus_driver_handle_release_service (DBusConnection *connection, DBusString service_name; const char *name; dbus_uint32_t service_reply; - dbus_bool_t retval; + BusResult retval; BusRegistry *registry; _DBUS_ASSERT_ERROR_IS_CLEAR (error); @@ -696,11 +704,11 @@ bus_driver_handle_release_service (DBusConnection *connection, if (!dbus_message_get_args (message, error, DBUS_TYPE_STRING, &name, DBUS_TYPE_INVALID)) - return FALSE; + return BUS_RESULT_FALSE; _dbus_verbose ("Trying to release name %s\n", name); - retval = FALSE; + retval = BUS_RESULT_FALSE; reply = NULL; _dbus_string_init_const (&service_name, name); @@ -729,7 +737,7 @@ bus_driver_handle_release_service (DBusConnection *connection, goto out; } - retval = TRUE; + retval = BUS_RESULT_TRUE; out: if (reply) @@ -737,7 +745,7 @@ bus_driver_handle_release_service (DBusConnection *connection, return retval; } -static dbus_bool_t +static BusResult bus_driver_handle_service_exists (DBusConnection *connection, BusTransaction *transaction, DBusMessage *message, @@ -748,7 +756,7 @@ bus_driver_handle_service_exists (DBusConnection *connection, BusService *service; dbus_bool_t service_exists; const char *name; - dbus_bool_t retval; + BusResult retval; BusRegistry *registry; _DBUS_ASSERT_ERROR_IS_CLEAR (error); @@ -758,9 +766,9 @@ bus_driver_handle_service_exists (DBusConnection *connection, if (!dbus_message_get_args (message, error, DBUS_TYPE_STRING, &name, DBUS_TYPE_INVALID)) - return FALSE; + return BUS_RESULT_FALSE; - retval = FALSE; + retval = BUS_RESULT_FALSE; if (strcmp (name, DBUS_SERVICE_DBUS) == 0) { @@ -794,7 +802,7 @@ bus_driver_handle_service_exists (DBusConnection *connection, goto out; } - retval = TRUE; + retval = BUS_RESULT_TRUE; out: if (reply) @@ -811,7 +819,7 @@ bus_driver_handle_activate_service (DBusConnection *connection, { dbus_uint32_t flags; const char *name; - dbus_bool_t retval; + BusResult retval; BusActivation *activation; _DBUS_ASSERT_ERROR_IS_CLEAR (error); @@ -825,10 +833,10 @@ bus_driver_handle_activate_service (DBusConnection *connection, { _DBUS_ASSERT_ERROR_IS_SET (error); _dbus_verbose ("No memory to get arguments to StartServiceByName\n"); - return FALSE; + return BUS_RESULT_FALSE; } - retval = FALSE; + retval = BUS_RESULT_FALSE; if (!bus_activation_activate_service (activation, connection, transaction, FALSE, message, name, error)) @@ -838,7 +846,7 @@ bus_driver_handle_activate_service (DBusConnection *connection, goto out; } - retval = TRUE; + retval = BUS_RESULT_TRUE; out: return retval; @@ -874,13 +882,13 @@ send_ack_reply (DBusConnection *connection, return TRUE; } -static dbus_bool_t +static BusResult bus_driver_handle_update_activation_environment (DBusConnection *connection, BusTransaction *transaction, DBusMessage *message, DBusError *error) { - dbus_bool_t retval; + BusResult retval; BusActivation *activation; DBusMessageIter iter; DBusMessageIter dict_iter; @@ -903,7 +911,7 @@ bus_driver_handle_update_activation_environment (DBusConnection *connection, dbus_message_iter_recurse (&iter, &dict_iter); - retval = FALSE; + retval = BUS_RESULT_FALSE; /* Then loop through the sent dictionary, add the location of * the environment keys and values to lists. The result will @@ -990,7 +998,7 @@ bus_driver_handle_update_activation_environment (DBusConnection *connection, message, error)) goto out; - retval = TRUE; + retval = BUS_RESULT_TRUE; out: _dbus_list_clear (&keys); @@ -998,7 +1006,7 @@ bus_driver_handle_update_activation_environment (DBusConnection *connection, return retval; } -static dbus_bool_t +static BusResult bus_driver_handle_add_match (DBusConnection *connection, BusTransaction *transaction, DBusMessage *message, @@ -1057,16 +1065,16 @@ bus_driver_handle_add_match (DBusConnection *connection, bus_match_rule_unref (rule); - return TRUE; + return BUS_RESULT_TRUE; failed: _DBUS_ASSERT_ERROR_IS_SET (error); if (rule) bus_match_rule_unref (rule); - return FALSE; + return BUS_RESULT_FALSE; } -static dbus_bool_t +static BusResult bus_driver_handle_remove_match (DBusConnection *connection, BusTransaction *transaction, DBusMessage *message, @@ -1110,16 +1118,16 @@ bus_driver_handle_remove_match (DBusConnection *connection, bus_match_rule_unref (rule); - return TRUE; + return BUS_RESULT_TRUE; failed: _DBUS_ASSERT_ERROR_IS_SET (error); if (rule) bus_match_rule_unref (rule); - return FALSE; + return BUS_RESULT_FALSE; } -static dbus_bool_t +static BusResult bus_driver_handle_get_service_owner (DBusConnection *connection, BusTransaction *transaction, DBusMessage *message, @@ -1189,7 +1197,7 @@ bus_driver_handle_get_service_owner (DBusConnection *connection, dbus_message_unref (reply); - return TRUE; + return BUS_RESULT_TRUE; oom: BUS_SET_OOM (error); @@ -1198,10 +1206,10 @@ bus_driver_handle_get_service_owner (DBusConnection *connection, _DBUS_ASSERT_ERROR_IS_SET (error); if (reply) dbus_message_unref (reply); - return FALSE; + return BUS_RESULT_FALSE; } -static dbus_bool_t +static BusResult bus_driver_handle_list_queued_owners (DBusConnection *connection, BusTransaction *transaction, DBusMessage *message, @@ -1292,7 +1300,7 @@ bus_driver_handle_list_queued_owners (DBusConnection *connection, dbus_message_unref (reply); - return TRUE; + return BUS_RESULT_TRUE; oom: BUS_SET_OOM (error); @@ -1305,10 +1313,10 @@ bus_driver_handle_list_queued_owners (DBusConnection *connection, if (base_names) _dbus_list_clear (&base_names); - return FALSE; + return BUS_RESULT_FALSE; } -static dbus_bool_t +static BusResult bus_driver_handle_get_connection_unix_user (DBusConnection *connection, BusTransaction *transaction, DBusMessage *message, @@ -1353,7 +1361,7 @@ bus_driver_handle_get_connection_unix_user (DBusConnection *connection, dbus_message_unref (reply); - return TRUE; + return BUS_RESULT_TRUE; oom: BUS_SET_OOM (error); @@ -1362,10 +1370,10 @@ bus_driver_handle_get_connection_unix_user (DBusConnection *connection, _DBUS_ASSERT_ERROR_IS_SET (error); if (reply) dbus_message_unref (reply); - return FALSE; + return BUS_RESULT_FALSE; } -static dbus_bool_t +static BusResult bus_driver_handle_get_connection_unix_process_id (DBusConnection *connection, BusTransaction *transaction, DBusMessage *message, @@ -1410,7 +1418,7 @@ bus_driver_handle_get_connection_unix_process_id (DBusConnection *connection, dbus_message_unref (reply); - return TRUE; + return BUS_RESULT_TRUE; oom: BUS_SET_OOM (error); @@ -1419,10 +1427,10 @@ bus_driver_handle_get_connection_unix_process_id (DBusConnection *connection, _DBUS_ASSERT_ERROR_IS_SET (error); if (reply) dbus_message_unref (reply); - return FALSE; + return BUS_RESULT_FALSE; } -static dbus_bool_t +static BusResult bus_driver_handle_get_adt_audit_session_data (DBusConnection *connection, BusTransaction *transaction, DBusMessage *message, @@ -1466,7 +1474,7 @@ bus_driver_handle_get_adt_audit_session_data (DBusConnection *connection, dbus_message_unref (reply); - return TRUE; + return BUS_RESULT_TRUE; oom: BUS_SET_OOM (error); @@ -1475,10 +1483,10 @@ bus_driver_handle_get_adt_audit_session_data (DBusConnection *connection, _DBUS_ASSERT_ERROR_IS_SET (error); if (reply) dbus_message_unref (reply); - return FALSE; + return BUS_RESULT_FALSE; } -static dbus_bool_t +static BusResult bus_driver_handle_get_connection_selinux_security_context (DBusConnection *connection, BusTransaction *transaction, DBusMessage *message, @@ -1520,7 +1528,7 @@ bus_driver_handle_get_connection_selinux_security_context (DBusConnection *conne dbus_message_unref (reply); - return TRUE; + return BUS_RESULT_TRUE; oom: BUS_SET_OOM (error); @@ -1529,10 +1537,10 @@ bus_driver_handle_get_connection_selinux_security_context (DBusConnection *conne _DBUS_ASSERT_ERROR_IS_SET (error); if (reply) dbus_message_unref (reply); - return FALSE; + return BUS_RESULT_FALSE; } -static dbus_bool_t +static BusResult bus_driver_handle_get_connection_credentials (DBusConnection *connection, BusTransaction *transaction, DBusMessage *message, @@ -1599,7 +1607,7 @@ bus_driver_handle_get_connection_credentials (DBusConnection *connection, goto oom; } - return TRUE; + return BUS_RESULT_TRUE; oom: BUS_SET_OOM (error); @@ -1613,10 +1621,10 @@ bus_driver_handle_get_connection_credentials (DBusConnection *connection, dbus_message_unref (reply); } - return FALSE; + return BUS_RESULT_FALSE; } -static dbus_bool_t +static BusResult bus_driver_handle_reload_config (DBusConnection *connection, BusTransaction *transaction, DBusMessage *message, @@ -1641,7 +1649,7 @@ bus_driver_handle_reload_config (DBusConnection *connection, goto oom; dbus_message_unref (reply); - return TRUE; + return BUS_RESULT_TRUE; oom: BUS_SET_OOM (error); @@ -1650,10 +1658,10 @@ bus_driver_handle_reload_config (DBusConnection *connection, _DBUS_ASSERT_ERROR_IS_SET (error); if (reply) dbus_message_unref (reply); - return FALSE; + return BUS_RESULT_FALSE; } -static dbus_bool_t +static BusResult bus_driver_handle_get_id (DBusConnection *connection, BusTransaction *transaction, DBusMessage *message, @@ -1669,7 +1677,7 @@ bus_driver_handle_get_id (DBusConnection *connection, if (!_dbus_string_init (&uuid)) { BUS_SET_OOM (error); - return FALSE; + return BUS_RESULT_FALSE; } reply = NULL; @@ -1695,7 +1703,7 @@ bus_driver_handle_get_id (DBusConnection *connection, _dbus_string_free (&uuid); dbus_message_unref (reply); - return TRUE; + return BUS_RESULT_TRUE; oom: _DBUS_ASSERT_ERROR_IS_CLEAR (error); @@ -1705,7 +1713,7 @@ bus_driver_handle_get_id (DBusConnection *connection, if (reply) dbus_message_unref (reply); _dbus_string_free (&uuid); - return FALSE; + return BUS_RESULT_FALSE; } typedef struct @@ -1713,10 +1721,10 @@ typedef struct const char *name; const char *in_args; const char *out_args; - dbus_bool_t (* handler) (DBusConnection *connection, - BusTransaction *transaction, - DBusMessage *message, - DBusError *error); + BusResult (* handler) (DBusConnection *connection, + BusTransaction *transaction, + DBusMessage *message, + DBusError *error); } MessageHandler; /* For speed it might be useful to sort this in order of @@ -1931,7 +1939,7 @@ bus_driver_generate_introspect_string (DBusString *xml) return TRUE; } -static dbus_bool_t +static BusResult bus_driver_handle_introspect (DBusConnection *connection, BusTransaction *transaction, DBusMessage *message, @@ -1951,13 +1959,13 @@ bus_driver_handle_introspect (DBusConnection *connection, DBUS_TYPE_INVALID)) { _DBUS_ASSERT_ERROR_IS_SET (error); - return FALSE; + return BUS_RESULT_FALSE; } if (!_dbus_string_init (&xml)) { BUS_SET_OOM (error); - return FALSE; + return BUS_RESULT_FALSE; } if (!bus_driver_generate_introspect_string (&xml)) @@ -1980,7 +1988,7 @@ bus_driver_handle_introspect (DBusConnection *connection, dbus_message_unref (reply); _dbus_string_free (&xml); - return TRUE; + return BUS_RESULT_TRUE; oom: BUS_SET_OOM (error); @@ -1990,10 +1998,10 @@ bus_driver_handle_introspect (DBusConnection *connection, _dbus_string_free (&xml); - return FALSE; + return BUS_RESULT_FALSE; } -dbus_bool_t +BusResult bus_driver_handle_message (DBusConnection *connection, BusTransaction *transaction, DBusMessage *message, @@ -2017,7 +2025,7 @@ bus_driver_handle_message (DBusConnection *connection, if (dbus_message_get_type (message) != DBUS_MESSAGE_TYPE_METHOD_CALL) { _dbus_verbose ("Driver got a non-method-call message, ignoring\n"); - return TRUE; /* we just ignore this */ + return BUS_RESULT_TRUE; /* we just ignore this */ } /* may be NULL, which means "any interface will do" */ @@ -2059,20 +2067,23 @@ bus_driver_handle_message (DBusConnection *connection, name, dbus_message_get_signature (message), mh->in_args); _DBUS_ASSERT_ERROR_IS_SET (error); - return FALSE; + return BUS_RESULT_FALSE; } - if ((* mh->handler) (connection, transaction, message, error)) + switch ((* mh->handler) (connection, transaction, message, error)) { - _DBUS_ASSERT_ERROR_IS_CLEAR (error); - _dbus_verbose ("Driver handler succeeded\n"); - return TRUE; - } - else - { - _DBUS_ASSERT_ERROR_IS_SET (error); - _dbus_verbose ("Driver handler returned failure\n"); - return FALSE; + case BUS_RESULT_TRUE: + _DBUS_ASSERT_ERROR_IS_CLEAR (error); + _dbus_verbose ("Driver handler succeeded\n"); + return BUS_RESULT_TRUE; + case BUS_RESULT_FALSE: + _DBUS_ASSERT_ERROR_IS_SET (error); + _dbus_verbose ("Driver handler returned failure\n"); + return BUS_RESULT_FALSE; + case BUS_RESULT_LATER: + _DBUS_ASSERT_ERROR_IS_CLEAR (error); + _dbus_verbose ("Driver handler delayed message processing due to policy check\n"); + return BUS_RESULT_LATER; } } } @@ -2084,7 +2095,7 @@ bus_driver_handle_message (DBusConnection *connection, "%s does not understand message %s", DBUS_SERVICE_DBUS, name); - return FALSE; + return BUS_RESULT_FALSE; } void diff --git a/bus/driver.h b/bus/driver.h index 713b2764..88292667 100644 --- a/bus/driver.h +++ b/bus/driver.h @@ -28,7 +28,7 @@ #include "connection.h" void bus_driver_remove_connection (DBusConnection *connection); -dbus_bool_t bus_driver_handle_message (DBusConnection *connection, +BusResult bus_driver_handle_message (DBusConnection *connection, BusTransaction *transaction, DBusMessage *message, DBusError *error); diff --git a/bus/policy.c b/bus/policy.c index 914b5888..398f7dc9 100644 --- a/bus/policy.c +++ b/bus/policy.c @@ -1448,18 +1448,21 @@ bus_client_policy_check_can_receive (BusClientPolicy *policy, -static dbus_bool_t +static BusResult bus_rules_check_can_own (DBusList *rules, - const DBusString *service_name) + const DBusString *service_name, + DBusConnection *connection, + DBusMessage *message) { DBusList *link; - dbus_bool_t allowed; + BusResult result; + const char *privilege; /* rules is in the order the rules appeared * in the config file, i.e. last rule that applies wins */ - allowed = FALSE; + result = BUS_RESULT_FALSE; link = _dbus_list_get_first_link (&rules); while (link != NULL) { @@ -1495,17 +1498,45 @@ bus_rules_check_can_own (DBusList *rules, } /* Use this rule */ - allowed = rule->access == BUS_POLICY_RULE_ACCESS_ALLOW; + switch (rule->access) + { + case BUS_POLICY_RULE_ACCESS_ALLOW: + result = BUS_RESULT_TRUE; + break; + case BUS_POLICY_RULE_ACCESS_DENY: + result = BUS_RESULT_FALSE; + break; + case BUS_POLICY_RULE_ACCESS_CHECK: + result = BUS_RESULT_LATER; + privilege = rule->privilege; + break; + } } - return allowed; + if (result == BUS_RESULT_LATER) + { + BusContext *context = bus_connection_get_context(connection); + BusCheck *check = bus_context_get_check(context); + BusDeferredMessage *deferred_message; + + result = bus_check_privilege(check, message, connection, NULL, NULL, + privilege, BUS_DEFERRED_MESSAGE_CHECK_OWN, &deferred_message); + if (result == BUS_RESULT_LATER) + { + bus_deferred_message_disable_sender(deferred_message); + } + } + + return result; } -dbus_bool_t +BusResult bus_client_policy_check_can_own (BusClientPolicy *policy, - const DBusString *service_name) + const DBusString *service_name, + DBusConnection *connection, + DBusMessage *message) { - return bus_rules_check_can_own (policy->rules, service_name); + return bus_rules_check_can_own (policy->rules, service_name, connection, message); } #ifdef DBUS_ENABLE_EMBEDDED_TESTS @@ -1513,7 +1544,7 @@ dbus_bool_t bus_policy_check_can_own (BusPolicy *policy, const DBusString *service_name) { - return bus_rules_check_can_own (policy->default_rules, service_name); + return bus_rules_check_can_own (policy->default_rules, service_name, NULL, NULL); } #endif /* DBUS_ENABLE_EMBEDDED_TESTS */ diff --git a/bus/policy.h b/bus/policy.h index 08979d21..0a3258eb 100644 --- a/bus/policy.h +++ b/bus/policy.h @@ -173,8 +173,10 @@ BusResult bus_client_policy_check_can_receive (BusClientPolicy *polic dbus_int32_t *toggles, const char **privilege_param, BusDeferredMessage **deferred_message); -dbus_bool_t bus_client_policy_check_can_own (BusClientPolicy *policy, - const DBusString *service_name); +BusResult bus_client_policy_check_can_own (BusClientPolicy *policy, + const DBusString *service_name, + DBusConnection *connection, + DBusMessage *message); dbus_bool_t bus_client_policy_append_rule (BusClientPolicy *policy, BusPolicyRule *rule); void bus_client_policy_optimize (BusClientPolicy *policy); diff --git a/bus/services.c b/bus/services.c index 01a720ed..52e17ee6 100644 --- a/bus/services.c +++ b/bus/services.c @@ -374,16 +374,17 @@ bus_registry_list_services (BusRegistry *registry, return FALSE; } -dbus_bool_t +BusResult bus_registry_acquire_service (BusRegistry *registry, DBusConnection *connection, + DBusMessage *message, const DBusString *service_name, dbus_uint32_t flags, dbus_uint32_t *result, BusTransaction *transaction, DBusError *error) { - dbus_bool_t retval; + BusResult retval; DBusConnection *old_owner_conn; BusClientPolicy *policy; BusService *service; @@ -391,7 +392,7 @@ bus_registry_acquire_service (BusRegistry *registry, BusSELinuxID *sid; BusOwner *primary_owner; - retval = FALSE; + retval = BUS_RESULT_FALSE; if (!_dbus_validate_bus_name (service_name, 0, _dbus_string_get_length (service_name))) @@ -459,16 +460,22 @@ bus_registry_acquire_service (BusRegistry *registry, goto out; } - if (!bus_client_policy_check_can_own (policy, service_name)) + switch (bus_client_policy_check_can_own (policy, service_name, connection, message)) { - dbus_set_error (error, DBUS_ERROR_ACCESS_DENIED, - "Connection \"%s\" is not allowed to own the service \"%s\" due " - "to security policies in the configuration file", - bus_connection_is_active (connection) ? - bus_connection_get_name (connection) : - "(inactive)", - _dbus_string_get_const_data (service_name)); - goto out; + case BUS_RESULT_TRUE: + break; + case BUS_RESULT_FALSE: + dbus_set_error (error, DBUS_ERROR_ACCESS_DENIED, + "Connection \"%s\" is not allowed to own the service \"%s\" due " + "to security policies in the configuration file", + bus_connection_is_active (connection) ? + bus_connection_get_name (connection) : + "(inactive)", + _dbus_string_get_const_data (service_name)); + goto out; + case BUS_RESULT_LATER: + retval = BUS_RESULT_LATER; + goto out; } if (bus_connection_get_n_services_owned (connection) >= @@ -586,11 +593,11 @@ bus_registry_acquire_service (BusRegistry *registry, } activation = bus_context_get_activation (registry->context); - retval = bus_activation_send_pending_auto_activation_messages (activation, - service, - transaction, - error); - + if (bus_activation_send_pending_auto_activation_messages (activation, + service, + transaction, + error)) + retval = BUS_RESULT_TRUE; out: return retval; } diff --git a/bus/services.h b/bus/services.h index 056dd9fa..3df3dd7d 100644 --- a/bus/services.h +++ b/bus/services.h @@ -50,8 +50,9 @@ void bus_registry_foreach (BusRegistry *registry dbus_bool_t bus_registry_list_services (BusRegistry *registry, char ***listp, int *array_len); -dbus_bool_t bus_registry_acquire_service (BusRegistry *registry, +BusResult bus_registry_acquire_service (BusRegistry *registry, DBusConnection *connection, + DBusMessage *message, const DBusString *service_name, dbus_uint32_t flags, dbus_uint32_t *result, diff --git a/bus/smack.c b/bus/smack.c index 300d9dac..eb67ee6c 100644 --- a/bus/smack.c +++ b/bus/smack.c @@ -40,7 +40,7 @@ #define SMACK_READ_WRITE "RW" -dbus_bool_t +BusResult bus_smack_handle_get_connection_context (DBusConnection *connection, BusTransaction *transaction, DBusMessage *message, @@ -61,7 +61,7 @@ bus_smack_handle_get_connection_context (DBusConnection *connection, if (!dbus_message_get_args (message, error, DBUS_TYPE_STRING, &remote_end, DBUS_TYPE_INVALID)) - return FALSE; + return BUS_RESULT_FALSE; _dbus_verbose ("asked for label of connection %s\n", remote_end); @@ -72,7 +72,7 @@ bus_smack_handle_get_connection_context (DBusConnection *connection, { dbus_set_error (error, DBUS_ERROR_NAME_HAS_NO_OWNER, "Bus name '%s' has no owner", remote_end); - return FALSE; + return BUS_RESULT_FALSE; } remote_connection = bus_service_get_primary_owners_connection (service); @@ -100,7 +100,7 @@ bus_smack_handle_get_connection_context (DBusConnection *connection, dbus_message_unref (reply); - return TRUE; + return BUS_RESULT_TRUE; oom: BUS_SET_OOM (error); @@ -109,11 +109,11 @@ err: if (reply != NULL) dbus_message_unref (reply); - return FALSE; + return BUS_RESULT_FALSE; #else dbus_set_error (error, DBUS_ERROR_NOT_SUPPORTED, "SMACK support is not enabled"); - return FALSE; + return BUS_RESULT_FALSE; #endif } diff --git a/bus/stats.c b/bus/stats.c index 2bf86d66..8e31b26a 100644 --- a/bus/stats.c +++ b/bus/stats.c @@ -34,7 +34,7 @@ #ifdef DBUS_ENABLE_STATS -dbus_bool_t +BusResult bus_stats_handle_get_stats (DBusConnection *connection, BusTransaction *transaction, DBusMessage *message, @@ -100,17 +100,17 @@ bus_stats_handle_get_stats (DBusConnection *connection, goto oom; dbus_message_unref (reply); - return TRUE; + return BUS_RESULT_TRUE; oom: if (reply != NULL) dbus_message_unref (reply); BUS_SET_OOM (error); - return FALSE; + return BUS_RESULT_FALSE; } -dbus_bool_t +BusResult bus_stats_handle_get_connection_stats (DBusConnection *caller_connection, BusTransaction *transaction, DBusMessage *message, @@ -134,7 +134,7 @@ bus_stats_handle_get_connection_stats (DBusConnection *caller_connection, if (! dbus_message_get_args (message, error, DBUS_TYPE_STRING, &bus_name, DBUS_TYPE_INVALID)) - return FALSE; + return BUS_RESULT_FALSE; _dbus_string_init_const (&bus_name_str, bus_name); service = bus_registry_lookup (registry, &bus_name_str); @@ -143,7 +143,7 @@ bus_stats_handle_get_connection_stats (DBusConnection *caller_connection, { dbus_set_error (error, DBUS_ERROR_NAME_HAS_NO_OWNER, "Bus name '%s' has no owner", bus_name); - return FALSE; + return BUS_RESULT_FALSE; } stats_connection = bus_service_get_primary_owners_connection (service); @@ -205,14 +205,14 @@ bus_stats_handle_get_connection_stats (DBusConnection *caller_connection, goto oom; dbus_message_unref (reply); - return TRUE; + return BUS_RESULT_TRUE; oom: if (reply != NULL) dbus_message_unref (reply); BUS_SET_OOM (error); - return FALSE; + return BUS_RESULT_FALSE; } #endif |