dbus_bool_t
bus_transaction_capture (BusTransaction *transaction,
DBusConnection *sender,
+ DBusConnection *addressed_recipient,
DBusMessage *message)
{
BusConnections *connections;
* There's little point, since there is up to 1 per process. */
_dbus_assert (mm != NULL);
- if (!bus_matchmaker_get_recipients (mm, connections, sender, NULL, message,
- &recipients))
+ if (!bus_matchmaker_get_recipients (mm, connections, sender,
+ addressed_recipient, message, &recipients))
goto out;
for (link = _dbus_list_get_first_link (&recipients);
dbus_bool_t
bus_transaction_capture_error_reply (BusTransaction *transaction,
+ DBusConnection *addressed_recipient,
const DBusError *error,
DBusMessage *in_reply_to)
{
if (!dbus_message_set_sender (reply, DBUS_SERVICE_DBUS))
goto out;
- ret = bus_transaction_capture (transaction, NULL, reply);
+ ret = bus_transaction_capture (transaction, NULL, addressed_recipient, reply);
out:
dbus_message_unref (reply);
/* Capture it for monitors, even if the real recipient's receive policy
* does not allow it to receive this message from us (which would be odd).
*/
- if (!bus_transaction_capture (transaction, NULL, message))
+ if (!bus_transaction_capture (transaction, NULL, connection, message))
return FALSE;
/* If security policy doesn't allow the message, we would silently
transaction,
NULL, connection, connection, message, &error))
{
- if (!bus_transaction_capture_error_reply (transaction, &error, message))
+ if (!bus_transaction_capture_error_reply (transaction, connection,
+ &error, message))
{
bus_context_log (transaction->context, DBUS_SYSTEM_LOG_WARNING,
"message from dbus-daemon rejected but not enough "
message,
&stack_error))
{
- if (!bus_transaction_capture_error_reply (transaction, &stack_error,
- message))
+ if (!bus_transaction_capture_error_reply (transaction, sender,
+ &stack_error, message))
{
bus_context_log (context, DBUS_SYSTEM_LOG_WARNING,
"broadcast rejected, but not enough "
bus_connection_get_name (connection),
bus_connection_get_loginfo (connection));
- if (!bus_transaction_capture_error_reply (transaction, &stack_error,
- message))
+ if (!bus_transaction_capture_error_reply (transaction, sender,
+ &stack_error, message))
{
bus_context_log (context, DBUS_SYSTEM_LOG_WARNING,
"broadcast with Unix fd not delivered, but not "
*/
service_name = dbus_message_get_destination (message);
- if (!bus_transaction_capture (transaction, connection, message))
- {
- BUS_SET_OOM (&error);
- goto out;
- }
-
if (service_name &&
strcmp (service_name, DBUS_SERVICE_DBUS) == 0) /* to bus driver */
{
+ if (!bus_transaction_capture (transaction, connection, NULL, message))
+ {
+ BUS_SET_OOM (&error);
+ goto out;
+ }
+
if (!bus_context_check_security_policy (context, transaction,
connection, NULL, NULL, message, &error))
{
}
else if (!bus_connection_is_active (connection)) /* clients must talk to bus driver first */
{
+ if (!bus_transaction_capture (transaction, connection, NULL, message))
+ {
+ BUS_SET_OOM (&error);
+ goto out;
+ }
+
_dbus_verbose ("Received message from non-registered client. Disconnecting.\n");
dbus_connection_close (connection);
goto out;
if (service == NULL && dbus_message_get_auto_start (message))
{
BusActivation *activation;
+
+ if (!bus_transaction_capture (transaction, connection, NULL,
+ message))
+ {
+ BUS_SET_OOM (&error);
+ goto out;
+ }
+
/* We can't do the security policy check here, since the addressed
* recipient service doesn't exist yet. We do it before sending the
* message after the service has been created.
}
else if (service == NULL)
{
+ if (!bus_transaction_capture (transaction, connection,
+ NULL, message))
+ {
+ BUS_SET_OOM (&error);
+ goto out;
+ }
+
dbus_set_error (&error,
DBUS_ERROR_NAME_HAS_NO_OWNER,
"Name \"%s\" does not exist",
{
addressed_recipient = bus_service_get_primary_owners_connection (service);
_dbus_assert (addressed_recipient != NULL);
+
+ if (!bus_transaction_capture (transaction, connection,
+ addressed_recipient, message))
+ {
+ BUS_SET_OOM (&error);
+ goto out;
+ }
+ }
+ }
+ else /* service_name == NULL */
+ {
+ if (!bus_transaction_capture (transaction, connection, NULL, message))
+ {
+ BUS_SET_OOM (&error);
+ goto out;
}
}
FALSE
};
+static const char * const well_known_destination_match_rules[] = {
+ "destination='com.example.Recipient'",
+ NULL
+};
+
static Config forbidding_config = {
"valid-config-files/forbidding.conf",
NULL,
FALSE
};
+static Config well_known_destination_config = {
+ NULL,
+ well_known_destination_match_rules,
+ FALSE
+};
+
static Config no_rules_config = {
NULL,
no_match_rules,
}
static void
+take_well_known_name (Fixture *f,
+ DBusConnection *connection,
+ const char *name)
+{
+ int ret;
+
+ ret = dbus_bus_request_name (connection, name,
+ DBUS_NAME_FLAG_DO_NOT_QUEUE, &f->e);
+ test_assert_no_error (&f->e);
+ g_assert_cmpint (ret, ==, DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER);
+}
+
+static void
setup (Fixture *f,
gconstpointer context)
{
}
static void
-become_monitor (Fixture *f)
+become_monitor (Fixture *f,
+ const Config *config)
{
DBusMessage *m;
DBusPendingCall *pc;
dbus_connection_set_route_peer_messages (f->monitor, TRUE);
- if (f->config != NULL && f->config->match_rules != NULL)
- match_rules = f->config->match_rules;
+ if (config == NULL)
+ config = f->config;
+
+ if (config != NULL && config->match_rules != NULL)
+ match_rules = config->match_rules;
else
match_rules = wildcard_match_rules;
}
}
- become_monitor (f);
+ become_monitor (f, NULL);
while (!lost_unique || !lost_a || !lost_b || !lost_c)
{
dbus_bus_add_match (f->recipient, "type='signal'", &f->e);
test_assert_no_error (&f->e);
- become_monitor (f);
+ become_monitor (f, NULL);
m = dbus_message_new_signal ("/foo", "com.example.bar", "BroadcastSignal1");
dbus_connection_send (f->sender, m, NULL);
dbus_bus_add_match (f->recipient, "type='signal'", &f->e);
test_assert_no_error (&f->e);
- become_monitor (f);
+ become_monitor (f, NULL);
m = dbus_message_new_signal ("/foo", "com.example.CannotSend",
"BroadcastSignal1");
if (f->address == NULL)
return;
- become_monitor (f);
+ become_monitor (f, NULL);
m = dbus_message_new_signal ("/foo", "com.example.bar", "UnicastSignal1");
if (!dbus_message_set_destination (m, f->recipient_name))
if (f->address == NULL)
return;
- become_monitor (f);
+ become_monitor (f, NULL);
m = dbus_message_new_signal ("/foo", "com.example.CannotSend",
"UnicastSignal1");
if (f->address == NULL)
return;
- become_monitor (f);
+ become_monitor (f, NULL);
/* regression test for
* https://bugs.freedesktop.org/show_bug.cgi?id=90952 */
if (f->address == NULL)
return;
- become_monitor (f);
+ become_monitor (f, NULL);
m = dbus_message_new_method_call (f->recipient_name, "/foo",
"com.example.CannotSend", "Call1");
if (f->address == NULL)
return;
- become_monitor (f);
+ become_monitor (f, NULL);
res = dbus_bus_request_name (f->sender, "com.example.Sender",
DBUS_NAME_FLAG_DO_NOT_QUEUE, &f->e);
"eavesdrop='true',interface='com.example.Tedious'", &f->e);
test_assert_no_error (&f->e);
- become_monitor (f);
+ become_monitor (f, NULL);
m = dbus_message_new_signal ("/foo", "com.example.Interesting",
"UnicastSignal1");
g_assert (m == NULL);
}
+static void
+test_well_known_destination (Fixture *f,
+ gconstpointer context)
+{
+ DBusMessage *m;
+
+ if (f->address == NULL)
+ return;
+
+ take_well_known_name (f, f->recipient, "com.example.Recipient");
+ /* we don't expect_take_well_known_name here because the
+ * monitor isn't up yet */
+
+ become_monitor (f, NULL);
+
+ /* The sender sends a message to itself. It will not be observed. */
+ m = dbus_message_new_signal ("/foo", "com.example.bar", "Unobserved");
+ if (!dbus_message_set_destination (m, f->sender_name))
+ g_error ("OOM");
+ dbus_connection_send (f->sender, m, NULL);
+ dbus_message_unref (m);
+
+ /* The sender sends a message to the recipient by well-known name.
+ * It will be observed. */
+ m = dbus_message_new_signal ("/foo", "com.example.bar", "Observed1");
+ if (!dbus_message_set_destination (m, "com.example.Recipient"))
+ g_error ("OOM");
+ dbus_connection_send (f->sender, m, NULL);
+ dbus_message_unref (m);
+
+ /* The sender sends a message to the recipient by unique name.
+ * It will still be observed. */
+ m = dbus_message_new_signal ("/foo", "com.example.bar", "Observed2");
+ if (!dbus_message_set_destination (m, f->recipient_name))
+ g_error ("OOM");
+ dbus_connection_send (f->sender, m, NULL);
+ dbus_message_unref (m);
+
+ while (g_queue_get_length (&f->monitored) < 2)
+ test_main_context_iterate (f->ctx, TRUE);
+
+ m = g_queue_pop_head (&f->monitored);
+ assert_signal (m, f->sender_name, "/foo", "com.example.bar",
+ "Observed1", "", "com.example.Recipient");
+ dbus_message_unref (m);
+
+ m = g_queue_pop_head (&f->monitored);
+ assert_signal (m, f->sender_name, "/foo", "com.example.bar",
+ "Observed2", "", f->recipient_name);
+ dbus_message_unref (m);
+
+ m = g_queue_pop_head (&f->monitored);
+ g_assert (m == NULL);
+}
+
+static void
+test_unique_destination (Fixture *f,
+ gconstpointer context)
+{
+ DBusMessage *m;
+ Config config = {
+ NULL,
+ NULL, /* match rules */
+ FALSE
+ };
+ const gchar *match_rules[2] = { NULL, NULL };
+ gchar *rule;
+
+ if (f->address == NULL)
+ return;
+
+ take_well_known_name (f, f->recipient, "com.example.Recipient");
+ /* we don't expect_take_well_known_name here because the
+ * monitor isn't up yet */
+
+ rule = g_strdup_printf ("destination='%s'", f->recipient_name);
+ /* free it later */
+ g_test_queue_free (rule);
+ match_rules[0] = rule;
+ config.match_rules = match_rules;
+
+ become_monitor (f, &config);
+
+ /* The sender sends a message to itself. It will not be observed. */
+ m = dbus_message_new_signal ("/foo", "com.example.bar", "Unobserved");
+ if (!dbus_message_set_destination (m, f->sender_name))
+ g_error ("OOM");
+ dbus_connection_send (f->sender, m, NULL);
+ dbus_message_unref (m);
+
+ /* The sender sends a message to the recipient by well-known name.
+ * It will be observed. */
+ m = dbus_message_new_signal ("/foo", "com.example.bar", "Observed1");
+ if (!dbus_message_set_destination (m, "com.example.Recipient"))
+ g_error ("OOM");
+ dbus_connection_send (f->sender, m, NULL);
+ dbus_message_unref (m);
+
+ /* The sender sends a message to the recipient by unique name.
+ * It will still be observed. */
+ m = dbus_message_new_signal ("/foo", "com.example.bar", "Observed2");
+ if (!dbus_message_set_destination (m, f->recipient_name))
+ g_error ("OOM");
+ dbus_connection_send (f->sender, m, NULL);
+ dbus_message_unref (m);
+
+ while (g_queue_get_length (&f->monitored) < 2)
+ test_main_context_iterate (f->ctx, TRUE);
+
+ m = g_queue_pop_head (&f->monitored);
+ assert_signal (m, f->sender_name, "/foo", "com.example.bar",
+ "Observed1", "", "com.example.Recipient");
+ dbus_message_unref (m);
+
+ m = g_queue_pop_head (&f->monitored);
+ assert_signal (m, f->sender_name, "/foo", "com.example.bar",
+ "Observed2", "", f->recipient_name);
+ dbus_message_unref (m);
+
+ m = g_queue_pop_head (&f->monitored);
+ g_assert (m == NULL);
+}
+
#ifdef DBUS_UNIX
/* currently only used for the systemd activation test */
static void
/* currently only used for the systemd activation test */
static void
-take_well_known_name (Fixture *f,
- DBusConnection *connection,
- const char *name)
-{
- int ret;
-
- ret = dbus_bus_request_name (connection, name,
- DBUS_NAME_FLAG_DO_NOT_QUEUE, &f->e);
- test_assert_no_error (&f->e);
- g_assert_cmpint (ret, ==, DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER);
-}
-
-/* currently only used for the systemd activation test */
-static void
expect_take_well_known_name (Fixture *f,
DBusConnection *connection,
const char *name)
if (f->address == NULL)
return;
- become_monitor (f);
+ become_monitor (f, NULL);
/* The sender sends a message to an activatable service. */
m = dbus_message_new_signal ("/foo", "com.example.bar", "UnicastSignal1");
setup, test_dbus_daemon, teardown);
g_test_add ("/monitor/selective", Fixture, &selective_config,
setup, test_selective, teardown);
+ g_test_add ("/monitor/well-known-destination",
+ Fixture, &well_known_destination_config,
+ setup, test_well_known_destination, teardown);
+ g_test_add ("/monitor/unique-destination",
+ Fixture, NULL,
+ setup, test_unique_destination, teardown);
g_test_add ("/monitor/wildcard", Fixture, &wildcard_config,
setup, test_unicast_signal, teardown);
g_test_add ("/monitor/no-rule", Fixture, &no_rules_config,