Commit 6a65f480 authored by Havoc Pennington's avatar Havoc Pennington

2003-10-09 Havoc Pennington <hp@redhat.com>

        Make matching rules theoretically work (add parser).

	* bus/bus.c (bus_context_check_security_policy): fix up to handle
	the case where destination is explicitly specified as bus driver
	and someone else is eavesdropping.

	* bus/policy.c (bus_client_policy_check_can_receive): fix up
	definition of eavesdropping and assertion

	* tools/dbus-send.c (main): use dbus_message_type_from_string

	* bus/signals.c (bus_match_rule_parse): implement

	* dbus/dbus-message.c (dbus_message_type_from_string): new

	* dbus/dbus-errors.h (DBUS_ERROR_MATCH_RULE_INVALID): add
parent 79d03f94
2003-10-09 Havoc Pennington <hp@redhat.com>
Make matching rules theoretically work (add parser).
* bus/bus.c (bus_context_check_security_policy): fix up to handle
the case where destination is explicitly specified as bus driver
and someone else is eavesdropping.
* bus/policy.c (bus_client_policy_check_can_receive): fix up
definition of eavesdropping and assertion
* tools/dbus-send.c (main): use dbus_message_type_from_string
* bus/signals.c (bus_match_rule_parse): implement
* dbus/dbus-message.c (dbus_message_type_from_string): new
* dbus/dbus-errors.h (DBUS_ERROR_MATCH_RULE_INVALID): add
2003-10-02 Havoc Pennington <hp@pobox.com>
* glib/dbus-gproxy.c (dbus_gproxy_call_no_reply): rename from
......
......@@ -872,6 +872,19 @@ bus_context_get_max_match_rules_per_connection (BusContext *context)
return context->limits.max_match_rules_per_connection;
}
/*
* addressed_recipient is the recipient specified in the message.
*
* proposed_recipient is the recipient we're considering sending
* to right this second, and may be an eavesdropper.
*
* sender is the sender of the message.
*
* NULL for proposed_recipient or sender definitely means the bus driver.
*
* NULL for addressed_recipient may mean the bus driver, or may mean
* no destination was specified in the message (e.g. a signal).
*/
dbus_bool_t
bus_context_check_security_policy (BusContext *context,
DBusConnection *sender,
......@@ -883,15 +896,9 @@ bus_context_check_security_policy (BusContext *context,
BusClientPolicy *sender_policy;
BusClientPolicy *recipient_policy;
/* NULL sender, proposed_recipient means the bus driver. NULL
* addressed_recipient means the message didn't specify an explicit
* target. If proposed_recipient is NULL, then addressed_recipient
* is also NULL but is implicitly the bus driver.
*/
_dbus_assert (proposed_recipient == NULL ||
(dbus_message_get_destination (message) == NULL ||
addressed_recipient != NULL));
_dbus_assert (dbus_message_get_destination (message) == NULL || /* Signal */
(addressed_recipient != NULL ||
strcmp (dbus_message_get_destination (message), DBUS_SERVICE_ORG_FREEDESKTOP_DBUS) == 0)); /* Destination specified or is the bus driver */
if (sender != NULL)
{
......
......@@ -813,21 +813,6 @@ start_busconfig_child (BusConfigParser *parser,
}
}
static int
message_type_from_string (const char *type_str)
{
if (strcmp (type_str, "method_call") == 0)
return DBUS_MESSAGE_TYPE_METHOD_CALL;
if (strcmp (type_str, "method_return") == 0)
return DBUS_MESSAGE_TYPE_METHOD_RETURN;
else if (strcmp (type_str, "signal") == 0)
return DBUS_MESSAGE_TYPE_SIGNAL;
else if (strcmp (type_str, "error") == 0)
return DBUS_MESSAGE_TYPE_ERROR;
else
return DBUS_MESSAGE_TYPE_INVALID;
}
static dbus_bool_t
append_rule_from_element (BusConfigParser *parser,
const char *element_name,
......@@ -1027,7 +1012,7 @@ append_rule_from_element (BusConfigParser *parser,
message_type = DBUS_MESSAGE_TYPE_INVALID;
if (send_type != NULL)
{
message_type = message_type_from_string (send_type);
message_type = dbus_message_type_from_string (send_type);
if (message_type == DBUS_MESSAGE_TYPE_INVALID)
{
dbus_set_error (error, DBUS_ERROR_FAILED,
......@@ -1079,7 +1064,7 @@ append_rule_from_element (BusConfigParser *parser,
message_type = DBUS_MESSAGE_TYPE_INVALID;
if (receive_type != NULL)
{
message_type = message_type_from_string (receive_type);
message_type = dbus_message_type_from_string (receive_type);
if (message_type == DBUS_MESSAGE_TYPE_INVALID)
{
dbus_set_error (error, DBUS_ERROR_FAILED,
......
......@@ -920,7 +920,8 @@ check_add_match_all (BusContext *context,
if (message == NULL)
return TRUE;
if (!dbus_message_append_args (message, DBUS_TYPE_STRING, "", /* FIXME */
/* empty string match rule matches everything */
if (!dbus_message_append_args (message, DBUS_TYPE_STRING, "",
DBUS_TYPE_INVALID))
{
dbus_message_unref (message);
......
......@@ -913,6 +913,9 @@ bus_client_policy_check_can_send (BusClientPolicy *policy,
return allowed;
}
/* See docs on what the args mean on bus_context_check_security_policy()
* comment
*/
dbus_bool_t
bus_client_policy_check_can_receive (BusClientPolicy *policy,
BusRegistry *registry,
......@@ -924,20 +927,10 @@ bus_client_policy_check_can_receive (BusClientPolicy *policy,
DBusList *link;
dbus_bool_t allowed;
dbus_bool_t eavesdropping;
/* NULL sender, proposed_recipient means the bus driver. NULL
* addressed_recipient means the message didn't specify an explicit
* target. If proposed_recipient is NULL, then addressed_recipient
* is also NULL but is implicitly the bus driver.
*/
_dbus_assert (proposed_recipient == NULL ||
(dbus_message_get_destination (message) == NULL ||
addressed_recipient != NULL));
eavesdropping =
(proposed_recipient == NULL || /* explicitly to bus driver */
(addressed_recipient && addressed_recipient != proposed_recipient)); /* explicitly to a different recipient */
addressed_recipient != proposed_recipient &&
dbus_message_get_destination (message) != NULL;
/* policy->rules is in the order the rules appeared
* in the config file, i.e. last rule that applies wins
......
This diff is collapsed.
......@@ -73,6 +73,7 @@ struct DBusError
#define DBUS_ERROR_UNKNOWN_METHOD "org.freedesktop.DBus.Error.UnknownMethod"
#define DBUS_ERROR_TIMED_OUT "org.freedesktop.DBus.Error.TimedOut"
#define DBUS_ERROR_MATCH_RULE_NOT_FOUND "org.freedesktop.DBus.Error.MatchRuleNotFound"
#define DBUS_ERROR_MATCH_RULE_INVALID "org.freedesktop.DBus.Error.MatchRuleInvalid"
#define DBUS_ERROR_SPAWN_EXEC_FAILED "org.freedesktop.DBus.Error.Spawn.ExecFailed"
#define DBUS_ERROR_SPAWN_FORK_FAILED "org.freedesktop.DBus.Error.Spawn.ForkFailed"
#define DBUS_ERROR_SPAWN_CHILD_EXITED "org.freedesktop.DBus.Error.Spawn.ChildExited"
......
......@@ -5416,6 +5416,34 @@ dbus_message_get_data (DBusMessage *message,
return res;
}
/**
* Utility function to convert a machine-readable (not translated)
* string into a D-BUS message type.
*
* @code
* "method_call" -> DBUS_MESSAGE_TYPE_METHOD_CALL
* "method_return" -> DBUS_MESSAGE_TYPE_METHOD_RETURN
* "signal" -> DBUS_MESSAGE_TYPE_SIGNAL
* "error" -> DBUS_MESSAGE_TYPE_ERROR
* anything else -> DBUS_MESSAGE_TYPE_INVALID
* @endcode
*
*/
int
dbus_message_type_from_string (const char *type_str)
{
if (strcmp (type_str, "method_call") == 0)
return DBUS_MESSAGE_TYPE_METHOD_CALL;
if (strcmp (type_str, "method_return") == 0)
return DBUS_MESSAGE_TYPE_METHOD_RETURN;
else if (strcmp (type_str, "signal") == 0)
return DBUS_MESSAGE_TYPE_SIGNAL;
else if (strcmp (type_str, "error") == 0)
return DBUS_MESSAGE_TYPE_ERROR;
else
return DBUS_MESSAGE_TYPE_INVALID;
}
/** @} */
#ifdef DBUS_BUILD_TESTS
#include "dbus-test.h"
......
......@@ -275,6 +275,8 @@ dbus_bool_t dbus_message_set_data (DBusMessage *message,
void* dbus_message_get_data (DBusMessage *message,
dbus_int32_t slot);
int dbus_message_type_from_string (const char *type_str);
DBUS_END_DECLS;
#endif /* DBUS_MESSAGE_H */
......@@ -86,11 +86,9 @@ main (int argc, char *argv[])
if (type_str != NULL)
{
if (strcmp (type_str, "method_call") == 0)
message_type = DBUS_MESSAGE_TYPE_METHOD_CALL;
else if (strcmp (type_str, "signal") == 0)
message_type = DBUS_MESSAGE_TYPE_SIGNAL;
else
message_type = dbus_message_type_from_string (type_str);
if (!(message_type == DBUS_MESSAGE_TYPE_METHOD_CALL ||
message_type == DBUS_MESSAGE_TYPE_SIGNAL))
{
fprintf (stderr, "Message type \"%s\" is not supported\n",
type_str);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment