summaryrefslogtreecommitdiff
path: root/bus
diff options
context:
space:
mode:
authorSimon McVittie <simon.mcvittie@collabora.co.uk>2012-01-04 17:44:23 +0000
committerSimon McVittie <simon.mcvittie@collabora.co.uk>2012-01-04 17:44:23 +0000
commit5df8c3db12590edd68e968975a335da9d0415e5a (patch)
treedf1452c78f549722ccc8d8c3b1b7ac047a494681 /bus
parent5ec835dac93a084ff5f697a9b83b640689462e00 (diff)
downloaddbus-5df8c3db12590edd68e968975a335da9d0415e5a.tar.gz
Revert all changes since a36d4918a6f646e085
Someone seems to have merged part of master into 1.4. Again. Let's go back to the "last known good" point (the branch-point of some 1.4 branches I had locally), then we can cherry-pick the changes that should have gone in.
Diffstat (limited to 'bus')
-rw-r--r--bus/Makefile.am46
-rw-r--r--bus/activation-helper.c11
-rw-r--r--bus/activation.c67
-rw-r--r--bus/bus.c43
-rw-r--r--bus/config-parser.c11
-rw-r--r--bus/connection.c184
-rw-r--r--bus/connection.h13
-rw-r--r--bus/dir-watch-inotify.c17
-rw-r--r--bus/dir-watch-kqueue.c17
-rw-r--r--bus/dispatch.c1
-rw-r--r--bus/driver.c218
-rw-r--r--bus/expirelist.c15
-rw-r--r--bus/main.c30
-rw-r--r--bus/policy.c15
-rw-r--r--bus/services.c7
-rw-r--r--bus/signals.c609
-rw-r--r--bus/signals.h30
-rw-r--r--bus/test-main.c9
-rw-r--r--bus/test.c46
-rw-r--r--bus/test.h1
20 files changed, 468 insertions, 922 deletions
diff --git a/bus/Makefile.am b/bus/Makefile.am
index 6cbc09a6..a3ddb6cf 100644
--- a/bus/Makefile.am
+++ b/bus/Makefile.am
@@ -1,30 +1,10 @@
configdir=$(sysconfdir)/dbus-1
dbus_daemon_execdir = $(DBUS_DAEMONDIR)
-DBUS_BUS_LIBS = \
- $(XML_LIBS) \
- $(SELINUX_LIBS) \
- $(THREAD_LIBS) \
- $(ADT_LIBS) \
- $(NETWORK_libs) \
- $(NULL)
-
-DBUS_LAUNCHER_LIBS = \
- $(XML_LIBS) \
- $(THREAD_LIBS) \
- $(NETWORK_libs) \
- $(NULL)
-
-AM_CPPFLAGS = \
- -I$(top_srcdir) \
- $(XML_CFLAGS) \
+INCLUDES = -I$(top_srcdir) \
+ $(DBUS_BUS_CFLAGS) \
-DDBUS_SYSTEM_CONFIG_FILE=\""$(configdir)/system.conf"\" \
- -DDBUS_COMPILATION \
- -DDBUS_STATIC_BUILD \
- $(NULL)
-
-# if assertions are enabled, improve backtraces
-AM_LDFLAGS = @R_DYNAMIC_LDFLAG@
+ -DDBUS_COMPILATION
EFENCE=
@@ -93,8 +73,6 @@ BUS_SOURCES= \
services.h \
signals.c \
signals.h \
- stats.c \
- stats.h \
test.c \
test.h \
utils.c \
@@ -105,11 +83,14 @@ dbus_daemon_SOURCES= \
$(BUS_SOURCES) \
main.c
+dbus_daemon_CPPFLAGS = -DDBUS_STATIC_BUILD
dbus_daemon_LDADD= \
$(top_builddir)/dbus/libdbus-internal.la \
$(EFENCE) \
$(DBUS_BUS_LIBS)
+dbus_daemon_LDFLAGS=@R_DYNAMIC_LDFLAG@
+
LAUNCH_HELPER_SOURCES= \
$(XML_SOURCES) \
config-parser-common.c \
@@ -129,10 +110,13 @@ dbus_daemon_launch_helper_SOURCES= \
activation-helper-bin.c \
$(LAUNCH_HELPER_SOURCES)
+dbus_daemon_launch_helper_CPPFLAGS = -DDBUS_STATIC_BUILD
dbus_daemon_launch_helper_LDADD= \
$(top_builddir)/dbus/libdbus-internal.la \
$(DBUS_LAUNCHER_LIBS)
+dbus_daemon_launch_helper_LDFLAGS=@R_DYNAMIC_LDFLAG@
+
## we build another binary so we can do the launch testing without root privs.
## DO NOT INSTALL THIS FILE
dbus_daemon_launch_helper_test_SOURCES= \
@@ -143,8 +127,8 @@ dbus_daemon_launch_helper_test_LDADD= \
$(top_builddir)/dbus/libdbus-internal.la \
$(DBUS_LAUNCHER_LIBS)
-dbus_daemon_launch_helper_test_CPPFLAGS = \
- $(AM_CPPFLAGS) \
+dbus_daemon_launch_helper_test_LDFLAGS=@R_DYNAMIC_LDFLAG@
+dbus_daemon_launch_helper_test_CPPFLAGS= -DDBUS_STATIC_BUILD \
-DACTIVATION_LAUNCHER_TEST
## we build yet another binary so we can do the OOM tests
@@ -157,8 +141,8 @@ bus_test_launch_helper_LDADD= \
$(top_builddir)/dbus/libdbus-internal.la \
$(DBUS_LAUNCHER_LIBS)
-bus_test_launch_helper_CPPFLAGS = \
- $(AM_CPPFLAGS) \
+bus_test_launch_helper_LDFLAGS=@R_DYNAMIC_LDFLAG@
+bus_test_launch_helper_CPPFLAGS= -DDBUS_STATIC_BUILD \
-DACTIVATION_LAUNCHER_TEST \
-DACTIVATION_LAUNCHER_DO_OOM
@@ -199,13 +183,17 @@ bus_test_system_SOURCES= \
utils.h \
test-system.c
+bus_test_system_CPPFLAGS = -DDBUS_STATIC_BUILD
bus_test_system_LDADD=$(top_builddir)/dbus/libdbus-internal.la $(DBUS_BUS_LIBS)
+bus_test_system_LDFLAGS=@R_DYNAMIC_LDFLAG@
bus_test_SOURCES= \
$(BUS_SOURCES) \
test-main.c
+bus_test_CPPFLAGS = -DDBUS_STATIC_BUILD
bus_test_LDADD=$(top_builddir)/dbus/libdbus-internal.la $(DBUS_BUS_LIBS)
+bus_test_LDFLAGS=@R_DYNAMIC_LDFLAG@
## mop up the gcov files
clean-local:
diff --git a/bus/activation-helper.c b/bus/activation-helper.c
index ab9d6010..baba8f04 100644
--- a/bus/activation-helper.c
+++ b/bus/activation-helper.c
@@ -144,10 +144,10 @@ out_all:
static dbus_bool_t
clear_environment (DBusError *error)
{
- const char *starter_env = NULL;
-#ifdef DBUS_ENABLE_VERBOSE_MODE
const char *debug_env = NULL;
+ const char *starter_env = NULL;
+#ifdef DBUS_ENABLE_VERBOSE_MODE
/* are we debugging */
debug_env = _dbus_getenv ("DBUS_VERBOSE");
#endif
@@ -184,7 +184,6 @@ clear_environment (DBusError *error)
static dbus_bool_t
check_permissions (const char *dbus_user, DBusError *error)
{
-#ifndef ACTIVATION_LAUNCHER_TEST
uid_t uid, euid;
struct passwd *pw;
@@ -192,6 +191,7 @@ check_permissions (const char *dbus_user, DBusError *error)
uid = 0;
euid = 0;
+#ifndef ACTIVATION_LAUNCHER_TEST
/* bail out unless the dbus user is invoking the helper */
pw = getpwnam(dbus_user);
if (!pw)
@@ -403,15 +403,12 @@ get_correct_parser (BusConfigParser **parser, DBusError *error)
{
DBusString config_file;
dbus_bool_t retval;
-#ifdef ACTIVATION_LAUNCHER_TEST
const char *test_config_file;
-#endif
retval = FALSE;
-
-#ifdef ACTIVATION_LAUNCHER_TEST
test_config_file = NULL;
+#ifdef ACTIVATION_LAUNCHER_TEST
/* there is no _way_ we should be setuid if this define is set.
* but we should be doubly paranoid and check... */
if (getuid() != geteuid())
diff --git a/bus/activation.c b/bus/activation.c
index 2744e214..acb2aa89 100644
--- a/bus/activation.c
+++ b/bus/activation.c
@@ -143,6 +143,16 @@ bus_pending_activation_entry_free (BusPendingActivationEntry *entry)
dbus_free (entry);
}
+static void
+handle_timeout_callback (DBusTimeout *timeout,
+ void *data)
+{
+ BusPendingActivation *pending_activation = data;
+
+ while (!dbus_timeout_handle (pending_activation->timeout))
+ _dbus_wait_for_memory ();
+}
+
static BusPendingActivation *
bus_pending_activation_ref (BusPendingActivation *pending_activation)
{
@@ -169,7 +179,8 @@ bus_pending_activation_unref (BusPendingActivation *pending_activation)
if (pending_activation->timeout_added)
{
_dbus_loop_remove_timeout (bus_context_get_loop (pending_activation->activation->context),
- pending_activation->timeout);
+ pending_activation->timeout,
+ handle_timeout_callback, pending_activation);
pending_activation->timeout_added = FALSE;
}
@@ -884,6 +895,8 @@ bus_activation_new (BusContext *context,
DBusError *error)
{
BusActivation *activation;
+ DBusList *link;
+ char *dir;
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
@@ -1324,16 +1337,22 @@ handle_servicehelper_exit_error (int exit_code,
}
}
-static void
-pending_activation_finished_cb (DBusBabysitter *babysitter,
- void *data)
+static dbus_bool_t
+babysitter_watch_callback (DBusWatch *watch,
+ unsigned int condition,
+ void *data)
{
BusPendingActivation *pending_activation = data;
+ dbus_bool_t retval;
+ DBusBabysitter *babysitter;
dbus_bool_t uses_servicehelper;
- _dbus_assert (babysitter == pending_activation->babysitter);
+ babysitter = pending_activation->babysitter;
+
_dbus_babysitter_ref (babysitter);
+ retval = dbus_watch_handle (watch, condition);
+
/* There are two major cases here; are we the system bus or the session? Here this
* is distinguished by whether or not we use a setuid helper launcher. With the launch helper,
* some process exit codes are meaningful, processed by handle_servicehelper_exit_error.
@@ -1344,7 +1363,15 @@ pending_activation_finished_cb (DBusBabysitter *babysitter,
*/
uses_servicehelper = bus_context_get_servicehelper (pending_activation->activation->context) != NULL;
- /* strictly speaking this is redundant with the check in dbus-spawn now */
+ /* FIXME this is broken in the same way that
+ * connection watches used to be; there should be
+ * a separate callback for status change, instead
+ * of doing "if we handled a watch status might
+ * have changed"
+ *
+ * Fixing this lets us move dbus_watch_handle
+ * calls into dbus-mainloop.c
+ */
if (_dbus_babysitter_get_child_exited (babysitter))
{
DBusError error;
@@ -1404,6 +1431,8 @@ pending_activation_finished_cb (DBusBabysitter *babysitter,
}
_dbus_babysitter_unref (babysitter);
+
+ return retval;
}
static dbus_bool_t
@@ -1412,9 +1441,9 @@ add_babysitter_watch (DBusWatch *watch,
{
BusPendingActivation *pending_activation = data;
- return _dbus_loop_add_watch (
- bus_context_get_loop (pending_activation->activation->context),
- watch);
+ return _dbus_loop_add_watch (bus_context_get_loop (pending_activation->activation->context),
+ watch, babysitter_watch_callback, pending_activation,
+ NULL);
}
static void
@@ -1424,7 +1453,7 @@ remove_babysitter_watch (DBusWatch *watch,
BusPendingActivation *pending_activation = data;
_dbus_loop_remove_watch (bus_context_get_loop (pending_activation->activation->context),
- watch);
+ watch, babysitter_watch_callback, pending_activation);
}
static dbus_bool_t
@@ -1672,6 +1701,7 @@ bus_activation_activate_service (BusActivation *activation,
char **envp = NULL;
int argc;
dbus_bool_t retval;
+ DBusHashIter iter;
dbus_bool_t was_pending_activation;
DBusString command;
@@ -1833,7 +1863,10 @@ bus_activation_activate_service (BusActivation *activation,
}
if (!_dbus_loop_add_timeout (bus_context_get_loop (activation->context),
- pending_activation->timeout))
+ pending_activation->timeout,
+ handle_timeout_callback,
+ pending_activation,
+ NULL))
{
_dbus_verbose ("Failed to add timeout for pending activation\n");
@@ -2103,10 +2136,6 @@ bus_activation_activate_service (BusActivation *activation,
_dbus_assert (pending_activation->babysitter != NULL);
- _dbus_babysitter_set_result_function (pending_activation->babysitter,
- pending_activation_finished_cb,
- pending_activation);
-
if (!_dbus_babysitter_set_watch_functions (pending_activation->babysitter,
add_babysitter_watch,
remove_babysitter_watch,
@@ -2538,18 +2567,14 @@ bus_activation_service_reload_test (const DBusString *test_data_dir)
_dbus_assert_not_reached ("could not initiate service reload test");
if (!do_service_reload_test (&directory, FALSE))
- {
- /* Do nothing? */
- }
+ ; /* Do nothing? */
/* Do OOM tests */
if (!init_service_reload_test (&directory))
_dbus_assert_not_reached ("could not initiate service reload test");
if (!do_service_reload_test (&directory, TRUE))
- {
- /* Do nothing? */
- }
+ ; /* Do nothing? */
/* Cleanup test directory */
if (!cleanup_service_reload_test (&directory))
diff --git a/bus/bus.c b/bus/bus.c
index 748ee90a..6b0dc088 100644
--- a/bus/bus.c
+++ b/bus/bus.c
@@ -103,6 +103,19 @@ server_get_context (DBusServer *server)
}
static dbus_bool_t
+server_watch_callback (DBusWatch *watch,
+ unsigned int condition,
+ void *data)
+{
+ /* FIXME this can be done in dbus-mainloop.c
+ * if the code in activation.c for the babysitter
+ * watch handler is fixed.
+ */
+
+ return dbus_watch_handle (watch, condition);
+}
+
+static dbus_bool_t
add_server_watch (DBusWatch *watch,
void *data)
{
@@ -111,7 +124,9 @@ add_server_watch (DBusWatch *watch,
context = server_get_context (server);
- return _dbus_loop_add_watch (context->loop, watch);
+ return _dbus_loop_add_watch (context->loop,
+ watch, server_watch_callback, server,
+ NULL);
}
static void
@@ -123,7 +138,17 @@ remove_server_watch (DBusWatch *watch,
context = server_get_context (server);
- _dbus_loop_remove_watch (context->loop, watch);
+ _dbus_loop_remove_watch (context->loop,
+ watch, server_watch_callback, server);
+}
+
+
+static void
+server_timeout_callback (DBusTimeout *timeout,
+ void *data)
+{
+ /* can return FALSE on OOM but we just let it fire again later */
+ dbus_timeout_handle (timeout);
}
static dbus_bool_t
@@ -135,7 +160,8 @@ add_server_timeout (DBusTimeout *timeout,
context = server_get_context (server);
- return _dbus_loop_add_timeout (context->loop, timeout);
+ return _dbus_loop_add_timeout (context->loop,
+ timeout, server_timeout_callback, server, NULL);
}
static void
@@ -147,7 +173,8 @@ remove_server_timeout (DBusTimeout *timeout,
context = server_get_context (server);
- _dbus_loop_remove_timeout (context->loop, timeout);
+ _dbus_loop_remove_timeout (context->loop,
+ timeout, server_timeout_callback, server);
}
static void
@@ -481,6 +508,7 @@ process_config_every_time (BusContext *context,
DBusString full_address;
DBusList *link;
DBusList **dirs;
+ BusActivation *new_activation;
char *addr;
const char *servicehelper;
char *s;
@@ -687,6 +715,7 @@ bus_context_new (const DBusString *config_file,
dbus_bool_t systemd_activation,
DBusError *error)
{
+ DBusString log_prefix;
BusContext *context;
BusConfigParser *parser;
@@ -1391,6 +1420,9 @@ bus_context_check_security_policy (BusContext *context,
dbus_bool_t log;
int type;
dbus_bool_t requested_reply;
+ const char *sender_name;
+ const char *sender_loginfo;
+ const char *proposed_recipient_loginfo;
type = dbus_message_get_type (message);
dest = dbus_message_get_destination (message);
@@ -1556,6 +1588,9 @@ bus_context_check_security_policy (BusContext *context,
proposed_recipient,
message, &toggles, &log))
{
+ const char *msg = "Rejected send message, %d matched rules; "
+ "type=\"%s\", sender=\"%s\" (%s) interface=\"%s\" member=\"%s\" error name=\"%s\" requested_reply=%d destination=\"%s\" (%s))";
+
complain_about_message (context, DBUS_ERROR_ACCESS_DENIED,
"Rejected send message", toggles,
message, sender, proposed_recipient, requested_reply,
diff --git a/bus/config-parser.c b/bus/config-parser.c
index c636707f..f9432555 100644
--- a/bus/config-parser.c
+++ b/bus/config-parser.c
@@ -3271,12 +3271,11 @@ test_default_session_servicedirs (void)
DBusList *dirs;
DBusList *link;
DBusString progs;
+ const char *common_progs;
int i;
#ifdef DBUS_WIN
- const char *common_progs;
char buffer[1024];
-
if (_dbus_get_install_root(buffer, sizeof(buffer)))
{
strcat(buffer,DBUS_DATADIR);
@@ -3290,9 +3289,8 @@ test_default_session_servicedirs (void)
if (!_dbus_string_init (&progs))
_dbus_assert_not_reached ("OOM allocating progs");
-#ifndef DBUS_UNIX
common_progs = _dbus_getenv ("CommonProgramFiles");
-
+#ifndef DBUS_UNIX
if (common_progs)
{
if (!_dbus_string_append (&progs, common_progs))
@@ -3413,9 +3411,7 @@ test_default_system_servicedirs (void)
DBusList *dirs;
DBusList *link;
DBusString progs;
-#ifndef DBUS_UNIX
const char *common_progs;
-#endif
int i;
/* On Unix we don't actually use this variable, but it's easier to handle the
@@ -3423,9 +3419,8 @@ test_default_system_servicedirs (void)
if (!_dbus_string_init (&progs))
_dbus_assert_not_reached ("OOM allocating progs");
-#ifndef DBUS_UNIX
common_progs = _dbus_getenv ("CommonProgramFiles");
-
+#ifndef DBUS_UNIX
if (common_progs)
{
if (!_dbus_string_append (&progs, common_progs))
diff --git a/bus/connection.c b/bus/connection.c
index 26839529..8e7d222a 100644
--- a/bus/connection.c
+++ b/bus/connection.c
@@ -62,16 +62,6 @@ struct BusConnections
DBusTimeout *expire_timeout; /**< Timeout for expiring incomplete connections. */
int stamp; /**< Incrementing number */
BusExpireList *pending_replies; /**< List of pending replies */
-
-#ifdef DBUS_ENABLE_STATS
- int total_match_rules;
- int peak_match_rules;
- int peak_match_rules_per_conn;
-
- int total_bus_names;
- int peak_bus_names;
- int peak_bus_names_per_conn;
-#endif
};
static dbus_int32_t connection_data_slot = -1;
@@ -97,11 +87,6 @@ typedef struct
long connection_tv_sec; /**< Time when we connected (seconds component) */
long connection_tv_usec; /**< Time when we connected (microsec component) */
int stamp; /**< connections->stamp last time we were traversed */
-
-#ifdef DBUS_ENABLE_STATS
- int peak_match_rules;
- int peak_bus_names;
-#endif
} BusConnectionData;
static dbus_bool_t bus_pending_reply_expired (BusExpireList *list,
@@ -310,12 +295,30 @@ bus_connection_disconnected (DBusConnection *connection)
}
static dbus_bool_t
+connection_watch_callback (DBusWatch *watch,
+ unsigned int condition,
+ void *data)
+{
+ /* FIXME this can be done in dbus-mainloop.c
+ * if the code in activation.c for the babysitter
+ * watch handler is fixed.
+ */
+
+#if 0
+ _dbus_verbose ("Calling handle_watch\n");
+#endif
+ return dbus_watch_handle (watch, condition);
+}
+
+static dbus_bool_t
add_connection_watch (DBusWatch *watch,
void *data)
{
DBusConnection *connection = data;
- return _dbus_loop_add_watch (connection_get_loop (connection), watch);
+ return _dbus_loop_add_watch (connection_get_loop (connection),
+ watch, connection_watch_callback, connection,
+ NULL);
}
static void
@@ -324,7 +327,18 @@ remove_connection_watch (DBusWatch *watch,
{
DBusConnection *connection = data;
- _dbus_loop_remove_watch (connection_get_loop (connection), watch);
+ _dbus_loop_remove_watch (connection_get_loop (connection),
+ watch, connection_watch_callback, connection);
+}
+
+static void
+connection_timeout_callback (DBusTimeout *timeout,
+ void *data)
+{
+ /* DBusConnection *connection = data; */
+
+ /* can return FALSE on OOM but we just let it fire again later */
+ dbus_timeout_handle (timeout);
}
static dbus_bool_t
@@ -333,7 +347,8 @@ add_connection_timeout (DBusTimeout *timeout,
{
DBusConnection *connection = data;
- return _dbus_loop_add_timeout (connection_get_loop (connection), timeout);
+ return _dbus_loop_add_timeout (connection_get_loop (connection),
+ timeout, connection_timeout_callback, connection, NULL);
}
static void
@@ -342,7 +357,8 @@ remove_connection_timeout (DBusTimeout *timeout,
{
DBusConnection *connection = data;
- _dbus_loop_remove_timeout (connection_get_loop (connection), timeout);
+ _dbus_loop_remove_timeout (connection_get_loop (connection),
+ timeout, connection_timeout_callback, connection);
}
static void
@@ -403,6 +419,14 @@ free_connection_data (void *data)
dbus_free (d);
}
+static void
+call_timeout_callback (DBusTimeout *timeout,
+ void *data)
+{
+ /* can return FALSE on OOM but we just let it fire again later */
+ dbus_timeout_handle (timeout);
+}
+
BusConnections*
bus_connections_new (BusContext *context)
{
@@ -436,7 +460,8 @@ bus_connections_new (BusContext *context)
goto failed_4;
if (!_dbus_loop_add_timeout (bus_context_get_loop (context),
- connections->expire_timeout))
+ connections->expire_timeout,
+ call_timeout_callback, NULL, NULL))
goto failed_5;
connections->refcount = 1;
@@ -507,7 +532,8 @@ bus_connections_unref (BusConnections *connections)
bus_expire_list_free (connections->pending_replies);
_dbus_loop_remove_timeout (bus_context_get_loop (connections->context),
- connections->expire_timeout);
+ connections->expire_timeout,
+ call_timeout_callback, NULL);
_dbus_timeout_unref (connections->expire_timeout);
@@ -830,7 +856,12 @@ bus_connection_get_unix_groups (DBusConnection *connection,
int *n_groups,
DBusError *error)
{
+ BusConnectionData *d;
unsigned long uid;
+
+ d = BUS_CONNECTION_DATA (connection);
+
+ _dbus_assert (d != NULL);
*groups = NULL;
*n_groups = 0;
@@ -1193,16 +1224,6 @@ bus_connection_send_oom_error (DBusConnection *connection,
d->oom_preallocated = NULL;
}
-#ifdef DBUS_ENABLE_STATS
-static void
-update_peak (int *peak,
- int n)
-{
- if (*peak < n)
- *peak = n;
-}
-#endif
-
void
bus_connection_add_match_rule_link (DBusConnection *connection,
DBusList *link)
@@ -1215,15 +1236,6 @@ bus_connection_add_match_rule_link (DBusConnection *connection,
_dbus_list_append_link (&d->match_rules, link);
d->n_match_rules += 1;
-
-#ifdef DBUS_ENABLE_STATS
- update_peak (&d->peak_match_rules, d->n_match_rules);
- update_peak (&d->connections->peak_match_rules_per_conn, d->n_match_rules);
-
- d->connections->total_match_rules += 1;
- update_peak (&d->connections->peak_match_rules,
- d->connections->total_match_rules);
-#endif
}
dbus_bool_t
@@ -1255,10 +1267,6 @@ bus_connection_remove_match_rule (DBusConnection *connection,
d->n_match_rules -= 1;
_dbus_assert (d->n_match_rules >= 0);
-
-#ifdef DBUS_ENABLE_STATS
- d->connections->total_match_rules -= 1;
-#endif
}
int
@@ -1284,16 +1292,6 @@ bus_connection_add_owned_service_link (DBusConnection *connection,
_dbus_list_append_link (&d->services_owned, link);
d->n_services_owned += 1;
-
-#ifdef DBUS_ENABLE_STATS
- update_peak (&d->peak_bus_names, d->n_services_owned);
- update_peak (&d->connections->peak_bus_names_per_conn,
- d->n_services_owned);
-
- d->connections->total_bus_names += 1;
- update_peak (&d->connections->peak_bus_names,
- d->connections->total_bus_names);
-#endif
}
dbus_bool_t
@@ -1325,10 +1323,6 @@ bus_connection_remove_owned_service (DBusConnection *connection,
d->n_services_owned -= 1;
_dbus_assert (d->n_services_owned >= 0);
-
-#ifdef DBUS_ENABLE_STATS
- d->connections->total_bus_names -= 1;
-#endif
}
int
@@ -1446,7 +1440,13 @@ bus_connections_check_limits (BusConnections *connections,
DBusConnection *requesting_completion,
DBusError *error)
{
+ BusConnectionData *d;
unsigned long uid;
+
+ d = BUS_CONNECTION_DATA (requesting_completion);
+ _dbus_assert (d != NULL);
+
+ _dbus_assert (d->name == NULL);
if (connections->n_completed >=
bus_context_get_max_completed_connections (connections->context))
@@ -2306,71 +2306,3 @@ bus_transaction_add_cancel_hook (BusTransaction *transaction,
return TRUE;
}
-
-#ifdef DBUS_ENABLE_STATS
-int
-bus_connections_get_n_active (BusConnections *connections)
-{
- return connections->n_completed;
-}
-
-int
-bus_connections_get_n_incomplete (BusConnections *connections)
-{
- return connections->n_incomplete;
-}
-
-int
-bus_connections_get_total_match_rules (BusConnections *connections)
-{
- return connections->total_match_rules;
-}
-
-int
-bus_connections_get_peak_match_rules (BusConnections *connections)
-{
- return connections->peak_match_rules;
-}
-
-int
-bus_connections_get_peak_match_rules_per_conn (BusConnections *connections)
-{
- return connections->peak_match_rules_per_conn;
-}
-
-int
-bus_connections_get_total_bus_names (BusConnections *connections)
-{
- return connections->total_bus_names;
-}
-
-int
-bus_connections_get_peak_bus_names (BusConnections *connections)
-{
- return connections->peak_bus_names;
-}
-
-int
-bus_connections_get_peak_bus_names_per_conn (BusConnections *connections)
-{
- return connections->peak_bus_names_per_conn;
-}
-
-int
-bus_connection_get_peak_match_rules (DBusConnection *connection)
-{
- BusConnectionData *d;
-
- d = BUS_CONNECTION_DATA (connection);
- return d->peak_match_rules;
-}
-
-int
-bus_connection_get_peak_bus_names (DBusConnection *connection)
-{
- BusConnectionData *d;
-
- d = BUS_CONNECTION_DATA (connection);
- return d->peak_bus_names;
-}
-#endif /* DBUS_ENABLE_STATS */
diff --git a/bus/connection.h b/bus/connection.h
index c9360212..4b9a754b 100644
--- a/bus/connection.h
+++ b/bus/connection.h
@@ -138,17 +138,4 @@ dbus_bool_t bus_transaction_add_cancel_hook (BusTransaction *
void *data,
DBusFreeFunction free_data_function);
-/* called by stats.c, only present if DBUS_ENABLE_STATS */
-int bus_connections_get_n_active (BusConnections *connections);
-int bus_connections_get_n_incomplete (BusConnections *connections);
-int bus_connections_get_total_match_rules (BusConnections *connections);
-int bus_connections_get_peak_match_rules (BusConnections *connections);
-int bus_connections_get_peak_match_rules_per_conn (BusConnections *connections);
-int bus_connections_get_total_bus_names (BusConnections *connections);
-int bus_connections_get_peak_bus_names (BusConnections *connections);
-int bus_connections_get_peak_bus_names_per_conn (BusConnections *connections);
-
-int bus_connection_get_peak_match_rules (DBusConnection *connection);
-int bus_connection_get_peak_bus_names (DBusConnection *connection);
-
#endif /* BUS_CONNECTION_H */
diff --git a/bus/dir-watch-inotify.c b/bus/dir-watch-inotify.c
index 2e9be988..461b8ee3 100644
--- a/bus/dir-watch-inotify.c
+++ b/bus/dir-watch-inotify.c
@@ -50,6 +50,12 @@ static DBusWatch *watch = NULL;
static DBusLoop *loop = NULL;
static dbus_bool_t
+_inotify_watch_callback (DBusWatch *watch, unsigned int condition, void *data)
+{
+ return dbus_watch_handle (watch, condition);
+}
+
+static dbus_bool_t
_handle_inotify_watch (DBusWatch *passed_watch, unsigned int flags, void *data)
{
char buffer[INOTIFY_BUF_LEN];
@@ -198,18 +204,16 @@ _shutdown_inotify (void *data)
_set_watched_dirs_internal (&empty);
+ close (inotify_fd);
+ inotify_fd = -1;
if (watch != NULL)
{
- _dbus_loop_remove_watch (loop, watch);
- _dbus_watch_invalidate (watch);
+ _dbus_loop_remove_watch (loop, watch, _inotify_watch_callback, NULL);
_dbus_watch_unref (watch);
_dbus_loop_unref (loop);
}
watch = NULL;
loop = NULL;
-
- close (inotify_fd);
- inotify_fd = -1;
}
static int
@@ -246,7 +250,8 @@ _init_inotify (BusContext *context)
goto out;
}
- if (!_dbus_loop_add_watch (loop, watch))
+ if (!_dbus_loop_add_watch (loop, watch, _inotify_watch_callback,
+ NULL, NULL))
{
_dbus_warn ("Unable to add reload watch to main loop");
_dbus_watch_unref (watch);
diff --git a/bus/dir-watch-kqueue.c b/bus/dir-watch-kqueue.c
index ac6290cc..4e436eb1 100644
--- a/bus/dir-watch-kqueue.c
+++ b/bus/dir-watch-kqueue.c
@@ -50,6 +50,12 @@ static DBusWatch *watch = NULL;
static DBusLoop *loop = NULL;
static dbus_bool_t
+_kqueue_watch_callback (DBusWatch *watch, unsigned int condition, void *data)
+{
+ return dbus_watch_handle (watch, condition);
+}
+
+static dbus_bool_t
_handle_kqueue_watch (DBusWatch *watch, unsigned int flags, void *data)
{
struct kevent ev;
@@ -74,8 +80,7 @@ _handle_kqueue_watch (DBusWatch *watch, unsigned int flags, void *data)
kq = -1;
if (watch != NULL)
{
- _dbus_loop_remove_watch (loop, watch);
- _dbus_watch_invalidate (watch);
+ _dbus_loop_remove_watch (loop, watch, _kqueue_watch_callback, NULL);
_dbus_watch_unref (watch);
watch = NULL;
}
@@ -115,14 +120,14 @@ _init_kqueue (BusContext *context)
goto out;
}
- if (!_dbus_loop_add_watch (loop, watch))
+ if (!_dbus_loop_add_watch (loop, watch, _kqueue_watch_callback,
+ NULL, NULL))
{
_dbus_warn ("Unable to add reload watch to main loop");
- _dbus_watch_invalidate (watch);
- _dbus_watch_unref (watch);
- watch = NULL;
close (kq);
kq = -1;
+ _dbus_watch_unref (watch);
+ watch = NULL;
goto out;
}
}
diff --git a/bus/dispatch.c b/bus/dispatch.c
index dfe6f746..a80476cd 100644
--- a/bus/dispatch.c
+++ b/bus/dispatch.c
@@ -4773,6 +4773,7 @@ bus_unix_fds_passing_test(const DBusString *test_data_dir)
DBusConnection *foo, *bar;
DBusError error;
DBusMessage *m;
+ dbus_bool_t b;
int one[2], two[2], x, y, z;
char r;
diff --git a/bus/driver.c b/bus/driver.c
index 574e0f3d..cc8d1f26 100644
--- a/bus/driver.c
+++ b/bus/driver.c
@@ -30,7 +30,6 @@
#include "services.h"
#include "selinux.h"
#include "signals.h"
-#include "stats.h"
#include "utils.h"
#include <dbus/dbus-string.h>
#include <dbus/dbus-internals.h>
@@ -827,6 +826,7 @@ bus_driver_handle_update_activation_environment (DBusConnection *connection,
DBusMessageIter iter;
DBusMessageIter dict_iter;
DBusMessageIter dict_entry_iter;
+ int msg_type;
int array_type;
int key_type;
DBusList *keys, *key_link;
@@ -841,13 +841,9 @@ bus_driver_handle_update_activation_environment (DBusConnection *connection,
/* The message signature has already been checked for us,
* so let's just assert it's right.
*/
-#ifndef DBUS_DISABLE_ASSERT
- {
- int msg_type = dbus_message_iter_get_arg_type (&iter);
+ msg_type = dbus_message_iter_get_arg_type (&iter);
- _dbus_assert (msg_type == DBUS_TYPE_ARRAY);
- }
-#endif
+ _dbus_assert (msg_type == DBUS_TYPE_ARRAY);
dbus_message_iter_recurse (&iter, &dict_iter);
@@ -1648,7 +1644,11 @@ bus_driver_handle_get_id (DBusConnection *connection,
return FALSE;
}
-typedef struct
+/* For speed it might be useful to sort this in order of
+ * frequency of use (but doesn't matter with only a few items
+ * anyhow)
+ */
+static struct
{
const char *name;
const char *in_args;
@@ -1657,13 +1657,7 @@ typedef struct
BusTransaction *transaction,
DBusMessage *message,
DBusError *error);
-} MessageHandler;
-
-/* For speed it might be useful to sort this in order of
- * frequency of use (but doesn't matter with only a few items
- * anyhow)
- */
-static const MessageHandler dbus_message_handlers[] = {
+} message_handlers[] = {
{ "Hello",
"",
DBUS_TYPE_STRING_AS_STRING,
@@ -1735,52 +1729,7 @@ static const MessageHandler dbus_message_handlers[] = {
{ "GetId",
"",
DBUS_TYPE_STRING_AS_STRING,
- bus_driver_handle_get_id },
- { NULL, NULL, NULL, NULL }
-};
-
-static dbus_bool_t bus_driver_handle_introspect (DBusConnection *,
- BusTransaction *, DBusMessage *, DBusError *);
-
-static const MessageHandler introspectable_message_handlers[] = {
- { "Introspect", "", DBUS_TYPE_STRING_AS_STRING, bus_driver_handle_introspect },
- { NULL, NULL, NULL, NULL }
-};
-
-#ifdef DBUS_ENABLE_STATS
-static const MessageHandler stats_message_handlers[] = {
- { "GetStats", "", "a{sv}", bus_stats_handle_get_stats },
- { "GetConnectionStats", "s", "a{sv}", bus_stats_handle_get_connection_stats },
- { NULL, NULL, NULL, NULL }
-};
-#endif
-
-typedef struct {
- const char *name;
- const MessageHandler *message_handlers;
- const char *extra_introspection;
-} InterfaceHandler;
-
-/* These should ideally be sorted by frequency of use, although it
- * probably doesn't matter with this few items */
-static InterfaceHandler interface_handlers[] = {
- { DBUS_INTERFACE_DBUS, dbus_message_handlers,
- " <signal name=\"NameOwnerChanged\">\n"
- " <arg type=\"s\"/>\n"
- " <arg type=\"s\"/>\n"
- " <arg type=\"s\"/>\n"
- " </signal>\n"
- " <signal name=\"NameLost\">\n"
- " <arg type=\"s\"/>\n"
- " </signal>\n"
- " <signal name=\"NameAcquired\">\n"
- " <arg type=\"s\"/>\n"
- " </signal>\n" },
- { DBUS_INTERFACE_INTROSPECTABLE, introspectable_message_handlers, NULL },
-#ifdef DBUS_ENABLE_STATS
- { BUS_INTERFACE_STATS, stats_message_handlers, NULL },
-#endif
- { NULL, NULL, NULL }
+ bus_driver_handle_get_id }
};
static dbus_bool_t
@@ -1821,43 +1770,86 @@ write_args_for_direction (DBusString *xml,
dbus_bool_t
bus_driver_generate_introspect_string (DBusString *xml)
{
- const InterfaceHandler *ih;
- const MessageHandler *mh;
+ int i;
if (!_dbus_string_append (xml, DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE))
return FALSE;
if (!_dbus_string_append (xml, "<node>\n"))
return FALSE;
+ if (!_dbus_string_append_printf (xml, " <interface name=\"%s\">\n", DBUS_INTERFACE_INTROSPECTABLE))
+ return FALSE;
+ if (!_dbus_string_append (xml, " <method name=\"Introspect\">\n"))
+ return FALSE;
+ if (!_dbus_string_append_printf (xml, " <arg name=\"data\" direction=\"out\" type=\"%s\"/>\n", DBUS_TYPE_STRING_AS_STRING))
+ return FALSE;
+ if (!_dbus_string_append (xml, " </method>\n"))
+ return FALSE;
+ if (!_dbus_string_append (xml, " </interface>\n"))
+ return FALSE;
- for (ih = interface_handlers; ih->name != NULL; ih++)
+ if (!_dbus_string_append_printf (xml, " <interface name=\"%s\">\n",
+ DBUS_INTERFACE_DBUS))
+ return FALSE;
+
+ i = 0;
+ while (i < _DBUS_N_ELEMENTS (message_handlers))
{
- if (!_dbus_string_append_printf (xml, " <interface name=\"%s\">\n",
- ih->name))
+
+ if (!_dbus_string_append_printf (xml, " <method name=\"%s\">\n",
+ message_handlers[i].name))
return FALSE;
- for (mh = ih->message_handlers; mh->name != NULL; mh++)
- {
- if (!_dbus_string_append_printf (xml, " <method name=\"%s\">\n",
- mh->name))
- return FALSE;
+ if (!write_args_for_direction (xml, message_handlers[i].in_args, TRUE))
+ return FALSE;
- if (!write_args_for_direction (xml, mh->in_args, TRUE))
- return FALSE;
+ if (!write_args_for_direction (xml, message_handlers[i].out_args, FALSE))
+ return FALSE;
- if (!write_args_for_direction (xml, mh->out_args, FALSE))
- return FALSE;
+ if (!_dbus_string_append (xml, " </method>\n"))
+ return FALSE;
- if (!_dbus_string_append (xml, " </method>\n"))
- return FALSE;
- }
+ ++i;
+ }
- if (ih->extra_introspection != NULL &&
- !_dbus_string_append (xml, ih->extra_introspection))
- return FALSE;
+ if (!_dbus_string_append_printf (xml, " <signal name=\"NameOwnerChanged\">\n"))
+ return FALSE;
- if (!_dbus_string_append (xml, " </interface>\n"))
- return FALSE;
- }
+ if (!_dbus_string_append_printf (xml, " <arg type=\"s\"/>\n"))
+ return FALSE;
+
+ if (!_dbus_string_append_printf (xml, " <arg type=\"s\"/>\n"))
+ return FALSE;
+
+ if (!_dbus_string_append_printf (xml, " <arg type=\"s\"/>\n"))
+ return FALSE;
+
+ if (!_dbus_string_append_printf (xml, " </signal>\n"))
+ return FALSE;
+
+
+
+ if (!_dbus_string_append_printf (xml, " <signal name=\"NameLost\">\n"))
+ return FALSE;
+
+ if (!_dbus_string_append_printf (xml, " <arg type=\"s\"/>\n"))
+ return FALSE;
+
+ if (!_dbus_string_append_printf (xml, " </signal>\n"))
+ return FALSE;
+
+
+
+ if (!_dbus_string_append_printf (xml, " <signal name=\"NameAcquired\">\n"))
+ return FALSE;
+
+ if (!_dbus_string_append_printf (xml, " <arg type=\"s\"/>\n"))
+ return FALSE;
+
+ if (!_dbus_string_append_printf (xml, " </signal>\n"))
+ return FALSE;
+
+ if (!_dbus_string_append (xml, " </interface>\n"))
+ return FALSE;
if (!_dbus_string_append (xml, "</node>\n"))
return FALSE;
@@ -1933,10 +1925,8 @@ bus_driver_handle_message (DBusConnection *connection,
DBusMessage *message,
DBusError *error)
{
- const char *name, *interface;
- const InterfaceHandler *ih;
- const MessageHandler *mh;
- dbus_bool_t found_interface = FALSE;
+ const char *name, *sender, *interface;
+ int i;
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
@@ -1954,54 +1944,57 @@ bus_driver_handle_message (DBusConnection *connection,
return TRUE; /* we just ignore this */
}
- /* may be NULL, which means "any interface will do" */
+ if (dbus_message_is_method_call (message,
+ DBUS_INTERFACE_INTROSPECTABLE,
+ "Introspect"))
+ return bus_driver_handle_introspect (connection, transaction, message, error);
+
interface = dbus_message_get_interface (message);
+ if (interface == NULL)
+ interface = DBUS_INTERFACE_DBUS;
_dbus_assert (dbus_message_get_member (message) != NULL);
name = dbus_message_get_member (message);
+ sender = dbus_message_get_sender (message);
- _dbus_verbose ("Driver got a method call: %s\n", name);
-
- /* security checks should have kept this from getting here */
-#ifndef DBUS_DISABLE_ASSERT
+ if (strcmp (interface,
+ DBUS_INTERFACE_DBUS) != 0)
{
- const char *sender = dbus_message_get_sender (message);
-
- _dbus_assert (sender != NULL || strcmp (name, "Hello") == 0);
+ _dbus_verbose ("Driver got message to unknown interface \"%s\"\n",
+ interface);
+ goto unknown;
}
-#endif
- for (ih = interface_handlers; ih->name != NULL; ih++)
- {
- if (interface != NULL && strcmp (interface, ih->name) != 0)
- continue;
+ _dbus_verbose ("Driver got a method call: %s\n",
+ dbus_message_get_member (message));
- found_interface = TRUE;
+ /* security checks should have kept this from getting here */
+ _dbus_assert (sender != NULL || strcmp (name, "Hello") == 0);
- for (mh = ih->message_handlers; mh->name != NULL; mh++)
+ i = 0;
+ while (i < _DBUS_N_ELEMENTS (message_handlers))
+ {
+ if (strcmp (message_handlers[i].name, name) == 0)
{
- if (strcmp (mh->name, name) != 0)
- continue;
-
_dbus_verbose ("Found driver handler for %s\n", name);
- if (!dbus_message_has_signature (message, mh->in_args))
+ if (!dbus_message_has_signature (message, message_handlers[i].in_args))
{
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
_dbus_verbose ("Call to %s has wrong args (%s, expected %s)\n",
name, dbus_message_get_signature (message),
- mh->in_args);
+ message_handlers[i].in_args);
dbus_set_error (error, DBUS_ERROR_INVALID_ARGS,
"Call to %s has wrong args (%s, expected %s)\n",
name, dbus_message_get_signature (message),
- mh->in_args);
+ message_handlers[i].in_args);
_DBUS_ASSERT_ERROR_IS_SET (error);
return FALSE;
}
- if ((* mh->handler) (connection, transaction, message, error))
+ if ((* message_handlers[i].handler) (connection, transaction, message, error))
{
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
_dbus_verbose ("Driver handler succeeded\n");
@@ -2014,12 +2007,15 @@ bus_driver_handle_message (DBusConnection *connection,
return FALSE;
}
}
+
+ ++i;
}
+ unknown:
_dbus_verbose ("No driver handler for message \"%s\"\n",
name);
- dbus_set_error (error, found_interface ? DBUS_ERROR_UNKNOWN_METHOD : DBUS_ERROR_UNKNOWN_INTERFACE,
+ dbus_set_error (error, DBUS_ERROR_UNKNOWN_METHOD,
"%s does not understand message %s",
DBUS_SERVICE_DBUS, name);
diff --git a/bus/expirelist.c b/bus/expirelist.c
index 3c87c119..946a615c 100644
--- a/bus/expirelist.c
+++ b/bus/expirelist.c
@@ -40,6 +40,14 @@ struct BusExpireList
static dbus_bool_t expire_timeout_handler (void *data);
+static void
+call_timeout_callback (DBusTimeout *timeout,
+ void *data)
+{
+ /* can return FALSE on OOM but we just let it fire again later */
+ dbus_timeout_handle (timeout);
+}
+
BusExpireList*
bus_expire_list_new (DBusLoop *loop,
int expire_after,
@@ -65,7 +73,9 @@ bus_expire_list_new (DBusLoop *loop,
_dbus_timeout_set_enabled (list->timeout, FALSE);
- if (!_dbus_loop_add_timeout (list->loop, list->timeout))
+ if (!_dbus_loop_add_timeout (list->loop,
+ list->timeout,
+ call_timeout_callback, NULL, NULL))
goto failed;
return list;
@@ -84,7 +94,8 @@ bus_expire_list_free (BusExpireList *list)
{
_dbus_assert (list->items == NULL);
- _dbus_loop_remove_timeout (list->loop, list->timeout);
+ _dbus_loop_remove_timeout (list->loop, list->timeout,
+ call_timeout_callback, NULL);
_dbus_timeout_unref (list->timeout);
diff --git a/bus/main.c b/bus/main.c
index a0bf07c7..bec2939c 100644
--- a/bus/main.c
+++ b/bus/main.c
@@ -32,12 +32,12 @@
#ifdef HAVE_SIGNAL_H
#include <signal.h>
#endif
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
#ifdef HAVE_ERRNO_H
#include <errno.h>
#endif
-#ifdef HAVE_UNISTD_H
-#include <unistd.h> /* for write() and STDERR_FILENO */
-#endif
#include "selinux.h"
static BusContext *context;
@@ -48,7 +48,7 @@ static int reload_pipe[2];
#define RELOAD_READ_END 0
#define RELOAD_WRITE_END 1
-static void close_reload_pipe (DBusWatch **);
+static void close_reload_pipe (void);
typedef enum
{
@@ -231,7 +231,7 @@ handle_reload_watch (DBusWatch *watch,
_dbus_read_socket (reload_pipe[RELOAD_READ_END], &str, 1) != 1)
{
_dbus_warn ("Couldn't read from reload pipe.\n");
- close_reload_pipe (&watch);
+ close_reload_pipe ();
return TRUE;
}
@@ -286,6 +286,14 @@ handle_reload_watch (DBusWatch *watch,
return TRUE;
}
+static dbus_bool_t
+reload_watch_callback (DBusWatch *watch,
+ unsigned int condition,
+ void *data)
+{
+ return dbus_watch_handle (watch, condition);
+}
+
static void
setup_reload_pipe (DBusLoop *loop)
{
@@ -315,7 +323,8 @@ setup_reload_pipe (DBusLoop *loop)
exit (1);
}
- if (!_dbus_loop_add_watch (loop, watch))
+ if (!_dbus_loop_add_watch (loop, watch, reload_watch_callback,
+ NULL, NULL))
{
_dbus_warn ("Unable to add reload watch to main loop: %s\n",
error.message);
@@ -326,13 +335,8 @@ setup_reload_pipe (DBusLoop *loop)
}
static void
-close_reload_pipe (DBusWatch **watch)
+close_reload_pipe (void)
{
- _dbus_loop_remove_watch (bus_context_get_loop (context), *watch);
- _dbus_watch_invalidate (*watch);
- _dbus_watch_unref (*watch);
- *watch = NULL;
-
_dbus_close_socket (reload_pipe[RELOAD_READ_END], NULL);
reload_pipe[RELOAD_READ_END] = -1;
@@ -355,6 +359,7 @@ main (int argc, char **argv)
int i;
dbus_bool_t print_address;
dbus_bool_t print_pid;
+ dbus_bool_t is_session_bus;
int force_fork;
dbus_bool_t systemd_activation;
@@ -372,6 +377,7 @@ main (int argc, char **argv)
print_address = FALSE;
print_pid = FALSE;
+ is_session_bus = FALSE;
force_fork = FORK_FOLLOW_CONFIG_FILE;
systemd_activation = FALSE;
diff --git a/bus/policy.c b/bus/policy.c
index 34e84469..4841f47c 100644
--- a/bus/policy.c
+++ b/bus/policy.c
@@ -1280,3 +1280,18 @@ bus_client_policy_check_can_own (BusClientPolicy *policy,
return allowed;
}
+
+#ifdef DBUS_BUILD_TESTS
+
+dbus_bool_t
+bus_policy_test (const DBusString *test_data_dir)
+{
+ /* 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;
+}
+
+#endif /* DBUS_BUILD_TESTS */
diff --git a/bus/services.c b/bus/services.c
index 68a7022a..0a049257 100644
--- a/bus/services.c
+++ b/bus/services.c
@@ -385,6 +385,7 @@ bus_registry_acquire_service (BusRegistry *registry,
{
dbus_bool_t retval;
DBusConnection *old_owner_conn;
+ DBusConnection *current_owner_conn;
BusClientPolicy *policy;
BusService *service;
BusActivation *activation;
@@ -509,10 +510,12 @@ bus_registry_acquire_service (BusRegistry *registry,
primary_owner = bus_service_get_primary_owner (service);
if (primary_owner == NULL)
goto out;
-
+
+ current_owner_conn = primary_owner->conn;
+
if (old_owner_conn == NULL)
{
- _dbus_assert (primary_owner->conn == connection);
+ _dbus_assert (current_owner_conn == connection);
*result = DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER;
}
diff --git a/bus/signals.c b/bus/signals.c
index 28506d3f..c85a88df 100644
--- a/bus/signals.c
+++ b/bus/signals.c
@@ -47,11 +47,8 @@ struct BusMatchRule
int args_len;
};
-#define BUS_MATCH_ARG_NAMESPACE 0x4000000u
#define BUS_MATCH_ARG_IS_PATH 0x8000000u
-#define BUS_MATCH_ARG_FLAGS (BUS_MATCH_ARG_NAMESPACE | BUS_MATCH_ARG_IS_PATH)
-
BusMatchRule*
bus_match_rule_new (DBusConnection *matches_go_to)
{
@@ -138,9 +135,36 @@ match_rule_to_string (BusMatchRule *rule)
if (rule->flags & BUS_MATCH_MESSAGE_TYPE)
{
- if (!_dbus_string_append_printf (&str, "type='%s'",
- dbus_message_type_to_string (rule->message_type)))
- goto nomem;
+ if (rule->message_type == DBUS_MESSAGE_TYPE_INVALID)
+ {
+ if (!_dbus_string_append_printf (&str, "type='INVALID'"))
+ goto nomem;
+ }
+ else if (rule->message_type == DBUS_MESSAGE_TYPE_METHOD_CALL)
+ {
+ if (!_dbus_string_append_printf (&str, "type='method_call'"))
+ goto nomem;
+ }
+ else if (rule->message_type == DBUS_MESSAGE_TYPE_METHOD_RETURN)
+ {
+ if (!_dbus_string_append_printf (&str, "type='method_return'"))
+ goto nomem;
+ }
+ else if (rule->message_type == DBUS_MESSAGE_TYPE_ERROR)
+ {
+ if (!_dbus_string_append_printf (&str, "type='error'"))
+ goto nomem;
+ }
+ else if (rule->message_type == DBUS_MESSAGE_TYPE_SIGNAL)
+ {
+ if (!_dbus_string_append_printf (&str, "type='signal'"))
+ goto nomem;
+ }
+ else
+ {
+ if (!_dbus_string_append_printf (&str, "type='%d'", rule->message_type))
+ goto nomem;
+ }
}
if (rule->flags & BUS_MATCH_INTERFACE)
@@ -179,18 +203,6 @@ match_rule_to_string (BusMatchRule *rule)
goto nomem;
}
- if (rule->flags & BUS_MATCH_PATH_NAMESPACE)
- {
- if (_dbus_string_get_length (&str) > 0)
- {
- if (!_dbus_string_append (&str, ","))
- goto nomem;
- }
-
- if (!_dbus_string_append_printf (&str, "path_namespace='%s'", rule->path))
- goto nomem;
- }
-
if (rule->flags & BUS_MATCH_SENDER)
{
if (_dbus_string_get_length (&str) > 0)
@@ -215,20 +227,6 @@ match_rule_to_string (BusMatchRule *rule)
goto nomem;
}
- if (rule->flags & BUS_MATCH_CLIENT_IS_EAVESDROPPING)
- {
- if (_dbus_string_get_length (&str) > 0)
- {
- if (!_dbus_string_append (&str, ","))
- goto nomem;
- }
-
- if (!_dbus_string_append_printf (&str, "eavesdrop='%s'",
- (rule->flags & BUS_MATCH_CLIENT_IS_EAVESDROPPING) ?
- "true" : "false"))
- goto nomem;
- }
-
if (rule->flags & BUS_MATCH_ARGS)
{
int i;
@@ -240,7 +238,7 @@ match_rule_to_string (BusMatchRule *rule)
{
if (rule->args[i] != NULL)
{
- dbus_bool_t is_path, is_namespace;
+ dbus_bool_t is_path;
if (_dbus_string_get_length (&str) > 0)
{
@@ -249,13 +247,10 @@ match_rule_to_string (BusMatchRule *rule)
}
is_path = (rule->arg_lens[i] & BUS_MATCH_ARG_IS_PATH) != 0;
- is_namespace = (rule->arg_lens[i] & BUS_MATCH_ARG_NAMESPACE) != 0;
if (!_dbus_string_append_printf (&str,
"arg%d%s='%s'",
- i,
- is_path ? "path" :
- is_namespace ? "namespace" : "",
+ i, is_path ? "path" : "",
rule->args[i]))
goto nomem;
}
@@ -368,20 +363,9 @@ bus_match_rule_set_destination (BusMatchRule *rule,
return TRUE;
}
-void
-bus_match_rule_set_client_is_eavesdropping (BusMatchRule *rule,
- dbus_bool_t is_eavesdropping)
-{
- if (is_eavesdropping)
- rule->flags |= BUS_MATCH_CLIENT_IS_EAVESDROPPING;
- else
- rule->flags &= ~(BUS_MATCH_CLIENT_IS_EAVESDROPPING);
-}
-
dbus_bool_t
bus_match_rule_set_path (BusMatchRule *rule,
- const char *path,
- dbus_bool_t is_namespace)
+ const char *path)
{
char *new;
@@ -391,13 +375,7 @@ bus_match_rule_set_path (BusMatchRule *rule,
if (new == NULL)
return FALSE;
- rule->flags &= ~(BUS_MATCH_PATH|BUS_MATCH_PATH_NAMESPACE);
-
- if (is_namespace)
- rule->flags |= BUS_MATCH_PATH_NAMESPACE;
- else
- rule->flags |= BUS_MATCH_PATH;
-
+ rule->flags |= BUS_MATCH_PATH;
dbus_free (rule->path);
rule->path = new;
@@ -408,8 +386,7 @@ dbus_bool_t
bus_match_rule_set_arg (BusMatchRule *rule,
int arg,
const DBusString *value,
- dbus_bool_t is_path,
- dbus_bool_t is_namespace)
+ dbus_bool_t is_path)
{
int length;
char *new;
@@ -476,9 +453,6 @@ bus_match_rule_set_arg (BusMatchRule *rule,
if (is_path)
rule->arg_lens[arg] |= BUS_MATCH_ARG_IS_PATH;
- if (is_namespace)
- rule->arg_lens[arg] |= BUS_MATCH_ARG_NAMESPACE;
-
/* NULL termination didn't get busted */
_dbus_assert (rule->args[rule->args_len] == NULL);
_dbus_assert (rule->arg_lens[rule->args_len] == 0);
@@ -773,8 +747,7 @@ bus_match_rule_parse_arg_match (BusMatchRule *rule,
const DBusString *value,
DBusError *error)
{
- dbus_bool_t is_path = FALSE;
- dbus_bool_t is_namespace = FALSE;
+ dbus_bool_t is_path;
DBusString key_str;
unsigned long arg;
int length;
@@ -805,35 +778,17 @@ bus_match_rule_parse_arg_match (BusMatchRule *rule,
goto failed;
}
- if (end != length)
+ if (end != length &&
+ ((end + 4) != length ||
+ !_dbus_string_ends_with_c_str (&key_str, "path")))
{
- if ((end + strlen ("path")) == length &&
- _dbus_string_ends_with_c_str (&key_str, "path"))
- {
- is_path = TRUE;
- }
- else if (_dbus_string_equal_c_str (&key_str, "arg0namespace"))
- {
- int value_len = _dbus_string_get_length (value);
-
- is_namespace = TRUE;
-
- if (!_dbus_validate_bus_namespace (value, 0, value_len))
- {
- dbus_set_error (error, DBUS_ERROR_MATCH_RULE_INVALID,
- "arg0namespace='%s' is not a valid prefix of a bus name",
- _dbus_string_get_const_data (value));
- goto failed;
- }
- }
- else
- {
- dbus_set_error (error, DBUS_ERROR_MATCH_RULE_INVALID,
- "Key '%s' in match rule contains junk after argument number (%u). Only 'arg%upath' (for example) or 'arg0namespace' are valid", key, arg, arg);
- goto failed;
- }
+ dbus_set_error (error, DBUS_ERROR_MATCH_RULE_INVALID,
+ "Key '%s' in match rule contains junk after argument number. Only 'path' is optionally valid ('arg0path' for example).\n", key);
+ goto failed;
}
+ is_path = end != length;
+
/* If we didn't check this we could allocate a huge amount of RAM */
if (arg > DBUS_MAXIMUM_MATCH_RULE_ARG_NUMBER)
{
@@ -851,7 +806,7 @@ bus_match_rule_parse_arg_match (BusMatchRule *rule,
goto failed;
}
- if (!bus_match_rule_set_arg (rule, arg, value, is_path, is_namespace))
+ if (!bus_match_rule_set_arg (rule, arg, value, is_path))
{
BUS_SET_OOM (error);
goto failed;
@@ -1007,15 +962,12 @@ bus_match_rule_parse (DBusConnection *matches_go_to,
goto failed;
}
}
- else if (strcmp (key, "path") == 0 ||
- strcmp (key, "path_namespace") == 0)
+ else if (strcmp (key, "path") == 0)
{
- dbus_bool_t is_namespace = (strcmp (key, "path_namespace") == 0);
-
- if (rule->flags & (BUS_MATCH_PATH | BUS_MATCH_PATH_NAMESPACE))
+ if (rule->flags & BUS_MATCH_PATH)
{
dbus_set_error (error, DBUS_ERROR_MATCH_RULE_INVALID,
- "path or path_namespace specified twice in match rule\n");
+ "Key %s specified twice in match rule\n", key);
goto failed;
}
@@ -1026,7 +978,7 @@ bus_match_rule_parse (DBusConnection *matches_go_to,
goto failed;
}
- if (!bus_match_rule_set_path (rule, value, is_namespace))
+ if (!bus_match_rule_set_path (rule, value))
{
BUS_SET_OOM (error);
goto failed;
@@ -1054,31 +1006,6 @@ bus_match_rule_parse (DBusConnection *matches_go_to,
goto failed;
}
}
- else if (strcmp (key, "eavesdrop") == 0)
- {
- /* do not detect "eavesdrop" being used more than once in rule:
- * 1) it's not possible, it's only in the flags
- * 2) it might be used twice to disable eavesdropping when it's
- * automatically added (eg dbus-monitor/bustle) */
-
- /* we accept only "true|false" as possible values */
- if ((strcmp (value, "true") == 0))
- {
- bus_match_rule_set_client_is_eavesdropping (rule, TRUE);
- }
- else if (strcmp (value, "false") == 0)
- {
- bus_match_rule_set_client_is_eavesdropping (rule, FALSE);
- }
- else
- {
- dbus_set_error (error, DBUS_ERROR_MATCH_RULE_INVALID,
- "eavesdrop='%s' is invalid, "
- "it should be 'true' or 'false'\n",
- value);
- goto failed;
- }
- }
else if (strncmp (key, "arg", 3) == 0)
{
if (!bus_match_rule_parse_arg_match (rule, key, &tmp_str, error))
@@ -1388,7 +1315,7 @@ match_rule_equal (BusMatchRule *a,
if ((a->flags & BUS_MATCH_PATH) &&
strcmp (a->path, b->path) != 0)
return FALSE;
-
+
if ((a->flags & BUS_MATCH_INTERFACE) &&
strcmp (a->interface, b->interface) != 0)
return FALSE;
@@ -1401,9 +1328,6 @@ match_rule_equal (BusMatchRule *a,
strcmp (a->destination, b->destination) != 0)
return FALSE;
- /* we already compared the value of flags, and
- * BUS_MATCH_CLIENT_IS_EAVESDROPPING does not have another struct member */
-
if (a->flags & BUS_MATCH_ARGS)
{
int i;
@@ -1422,7 +1346,7 @@ match_rule_equal (BusMatchRule *a,
if (a->arg_lens[i] != b->arg_lens[i])
return FALSE;
- length = a->arg_lens[i] & ~BUS_MATCH_ARG_FLAGS;
+ length = a->arg_lens[i] & ~BUS_MATCH_ARG_IS_PATH;
if (a->args[i] != NULL)
{
@@ -1654,24 +1578,12 @@ connection_is_primary_owner (DBusConnection *connection,
}
static dbus_bool_t
-str_has_prefix (const char *str, const char *prefix)
-{
- size_t prefix_len;
- prefix_len = strlen (prefix);
- if (strncmp (str, prefix, prefix_len) == 0)
- return TRUE;
- else
- return FALSE;
-}
-
-static dbus_bool_t
match_rule_matches (BusMatchRule *rule,
DBusConnection *sender,
DBusConnection *addressed_recipient,
DBusMessage *message,
BusMatchFlags already_matched)
{
- dbus_bool_t wants_to_eavesdrop = FALSE;
int flags;
/* All features of the match rule are AND'd together,
@@ -1686,9 +1598,6 @@ match_rule_matches (BusMatchRule *rule,
/* Don't bother re-matching features we've already checked implicitly. */
flags = rule->flags & (~already_matched);
- if (flags & BUS_MATCH_CLIENT_IS_EAVESDROPPING)
- wants_to_eavesdrop = TRUE;
-
if (flags & BUS_MATCH_MESSAGE_TYPE)
{
_dbus_assert (rule->message_type != DBUS_MESSAGE_TYPE_INVALID);
@@ -1742,24 +1651,6 @@ match_rule_matches (BusMatchRule *rule,
}
}
- /* Note: this part is relevant for eavesdropper rules:
- * Two cases:
- * 1) rule has a destination to be matched
- * (flag BUS_MATCH_DESTINATION present). Rule will match if:
- * - rule->destination matches the addressed_recipient
- * AND
- * - wants_to_eavesdrop=TRUE
- *
- * Note: (the case in which addressed_recipient is the actual rule owner
- * is handled elsewere in dispatch.c:bus_dispatch_matches().
- *
- * 2) rule has no destination. Rule will match if:
- * - message has no specified destination (ie broadcasts)
- * (Note: this will rule out unicast method calls and unicast signals,
- * fixing FDO#269748)
- * OR
- * - wants_to_eavesdrop=TRUE (destination-catch-all situation)
- */
if (flags & BUS_MATCH_DESTINATION)
{
const char *destination;
@@ -1768,12 +1659,6 @@ match_rule_matches (BusMatchRule *rule,
destination = dbus_message_get_destination (message);
if (destination == NULL)
- /* broadcast, but this rule specified a destination: no match */
- return FALSE;
-
- /* rule owner does not intend to eavesdrop: we'll deliver only msgs
- * directed to it, NOT MATCHING */
- if (!wants_to_eavesdrop)
return FALSE;
if (addressed_recipient == NULL)
@@ -1787,19 +1672,6 @@ match_rule_matches (BusMatchRule *rule,
if (!connection_is_primary_owner (addressed_recipient, rule->destination))
return FALSE;
}
- } else { /* no destination in rule */
- dbus_bool_t msg_is_broadcast;
-
- _dbus_assert (rule->destination == NULL);
-
- msg_is_broadcast = (dbus_message_get_destination (message) == NULL);
-
- if (!wants_to_eavesdrop && !msg_is_broadcast)
- return FALSE;
-
- /* if we are here rule owner intends to eavesdrop
- * OR
- * message is being broadcasted */
}
if (flags & BUS_MATCH_PATH)
@@ -1816,31 +1688,6 @@ match_rule_matches (BusMatchRule *rule,
return FALSE;
}
- if (flags & BUS_MATCH_PATH_NAMESPACE)
- {
- const char *path;
- int len;
-
- _dbus_assert (rule->path != NULL);
-
- path = dbus_message_get_path (message);
- if (path == NULL)
- return FALSE;
-
- if (!str_has_prefix (path, rule->path))
- return FALSE;
-
- len = strlen (rule->path);
-
- /* Check that the actual argument is within the expected
- * namespace, rather than just starting with that string,
- * by checking that the matched prefix is followed by a '/'
- * or the end of the path.
- */
- if (path[len] != '\0' && path[len] != '/')
- return FALSE;
- }
-
if (flags & BUS_MATCH_ARGS)
{
int i;
@@ -1856,12 +1703,11 @@ match_rule_matches (BusMatchRule *rule,
int current_type;
const char *expected_arg;
int expected_length;
- dbus_bool_t is_path, is_namespace;
+ dbus_bool_t is_path;
expected_arg = rule->args[i];
- expected_length = rule->arg_lens[i] & ~BUS_MATCH_ARG_FLAGS;
+ expected_length = rule->arg_lens[i] & ~BUS_MATCH_ARG_IS_PATH;
is_path = (rule->arg_lens[i] & BUS_MATCH_ARG_IS_PATH) != 0;
- is_namespace = (rule->arg_lens[i] & BUS_MATCH_ARG_NAMESPACE) != 0;
current_type = dbus_message_iter_get_arg_type (&iter);
@@ -1869,9 +1715,8 @@ match_rule_matches (BusMatchRule *rule,
{
const char *actual_arg;
int actual_length;
-
- if (current_type != DBUS_TYPE_STRING &&
- (!is_path || current_type != DBUS_TYPE_OBJECT_PATH))
+
+ if (current_type != DBUS_TYPE_STRING)
return FALSE;
actual_arg = NULL;
@@ -1894,32 +1739,6 @@ match_rule_matches (BusMatchRule *rule,
MIN (actual_length, expected_length)) != 0)
return FALSE;
}
- else if (is_namespace)
- {
- if (expected_length > actual_length)
- return FALSE;
-
- /* If the actual argument doesn't start with the expected
- * namespace, then we don't match.
- */
- if (memcmp (expected_arg, actual_arg, expected_length) != 0)
- return FALSE;
-
- if (expected_length < actual_length)
- {
- /* Check that the actual argument is within the expected
- * namespace, rather than just starting with that string,
- * by checking that the matched prefix ends in a '.'.
- *
- * This doesn't stop "foo.bar." matching "foo.bar..baz"
- * which is an invalid namespace, but at some point the
- * daemon can't cover up for broken services.
- */
- if (actual_arg[expected_length] != '.')
- return FALSE;
- }
- /* otherwise we had an exact match. */
- }
else
{
if (expected_length != actual_length ||
@@ -2234,73 +2053,7 @@ test_parsing (void *data)
bus_match_rule_unref (rule);
}
-
- rule = check_parse (TRUE, "arg7path='/foo'");
- if (rule != NULL)
- {
- _dbus_assert (rule->flags = BUS_MATCH_ARGS);
- _dbus_assert (rule->args != NULL);
- _dbus_assert (rule->args_len == 8);
- _dbus_assert (rule->args[7] != NULL);
- _dbus_assert (rule->args[8] == NULL);
- _dbus_assert (strcmp (rule->args[7], "/foo") == 0);
- _dbus_assert ((rule->arg_lens[7] & BUS_MATCH_ARG_IS_PATH)
- == BUS_MATCH_ARG_IS_PATH);
-
- bus_match_rule_unref (rule);
- }
-
- /* Arg 0 namespace matches */
- rule = check_parse (TRUE, "arg0namespace='foo'");
- if (rule != NULL)
- {
- _dbus_assert (rule->flags == BUS_MATCH_ARGS);
- _dbus_assert (rule->args != NULL);
- _dbus_assert (rule->args_len == 1);
- _dbus_assert (strcmp (rule->args[0], "foo") == 0);
- _dbus_assert ((rule->arg_lens[0] & BUS_MATCH_ARG_NAMESPACE)
- == BUS_MATCH_ARG_NAMESPACE);
-
- bus_match_rule_unref (rule);
- }
-
- rule = check_parse (TRUE, "arg0namespace='foo.bar'");
- if (rule != NULL)
- {
- _dbus_assert (rule->flags == BUS_MATCH_ARGS);
- _dbus_assert (rule->args != NULL);
- _dbus_assert (rule->args_len == 1);
- _dbus_assert (strcmp (rule->args[0], "foo.bar") == 0);
- _dbus_assert ((rule->arg_lens[0] & BUS_MATCH_ARG_NAMESPACE)
- == BUS_MATCH_ARG_NAMESPACE);
-
- bus_match_rule_unref (rule);
- }
-
- /* Only arg0namespace is supported. */
- rule = check_parse (FALSE, "arg1namespace='foo'");
- _dbus_assert (rule == NULL);
-
- /* An empty string isn't a valid namespace prefix (you should just not
- * specify this key at all).
- */
- rule = check_parse (FALSE, "arg0namespace=''");
- _dbus_assert (rule == NULL);
-
- /* Trailing periods aren't allowed (earlier versions of the arg0namespace
- * spec allowed a single trailing period, which altered the semantics) */
- rule = check_parse (FALSE, "arg0namespace='foo.'");
- _dbus_assert (rule == NULL);
-
- rule = check_parse (FALSE, "arg0namespace='foo.bar.'");
- _dbus_assert (rule == NULL);
-
- rule = check_parse (FALSE, "arg0namespace='foo..'");
- _dbus_assert (rule == NULL);
-
- rule = check_parse (FALSE, "arg0namespace='foo.bar..'");
- _dbus_assert (rule == NULL);
-
+
/* Too-large argN */
rule = check_parse (FALSE, "arg300='foo'");
_dbus_assert (rule == NULL);
@@ -2321,24 +2074,6 @@ test_parsing (void *data)
rule = check_parse (FALSE, "type='signal',type='method_call'");
_dbus_assert (rule == NULL);
- rule = check_parse (TRUE, "path_namespace='/foo/bar'");
- if (rule != NULL)
- {
- _dbus_assert (rule->flags == BUS_MATCH_PATH_NAMESPACE);
- _dbus_assert (rule->path != NULL);
- _dbus_assert (strcmp (rule->path, "/foo/bar") == 0);
-
- bus_match_rule_unref (rule);
- }
-
- /* Almost a duplicate */
- rule = check_parse (FALSE, "path='/foo',path_namespace='/foo'");
- _dbus_assert (rule == NULL);
-
- /* Trailing / was supported in the initial proposal, but now isn't */
- rule = check_parse (FALSE, "path_namespace='/foo/'");
- _dbus_assert (rule == NULL);
-
/* Duplicates with the argN code */
rule = check_parse (FALSE, "arg0='foo',arg0='bar'");
_dbus_assert (rule == NULL);
@@ -2399,7 +2134,6 @@ static struct {
{ "type='method_call',arg0='blah',arg1='baz'", "arg0='blah',arg1='baz',type='method_call'" },
{ "type='method_call',arg3='foosh'", "arg3='foosh',type='method_call'" },
{ "arg3='fool'", "arg3='fool'" },
- { "arg0namespace='fool'", "arg0namespace='fool'" },
{ "member='food'", "member='food'" }
};
@@ -2469,13 +2203,6 @@ should_match_message_1[] = {
"type='signal',member='Frobated',arg0='foobar'",
"member='Frobated',arg0='foobar'",
"type='signal',arg0='foobar'",
- /* The definition of argXpath matches says: "As with normal argument matches,
- * if the argument is exactly equal to the string given in the match rule
- * then the rule is satisfied." So this should match (even though the
- * argument is not a valid path)!
- */
- "arg0path='foobar'",
- "arg0namespace='foobar'",
NULL
};
@@ -2494,44 +2221,6 @@ should_not_match_message_1[] = {
"arg0='foobar',arg1='abcdef'",
"arg0='foobar',arg1='abcdef',arg2='abcdefghi',arg3='abcdefghi',arg4='abcdefghi'",
"arg0='foobar',arg1='abcdef',arg4='abcdefghi',arg3='abcdefghi',arg2='abcdefghi'",
- "arg0path='foo'",
- "arg0path='foobar/'",
- "arg1path='3'",
- "arg0namespace='foo'",
- "arg0namespace='foo',arg1='abcdef'",
- "arg0namespace='moo'",
- NULL
-};
-
-#define EXAMPLE_NAME "com.example.backend.foo"
-
-static const char *
-should_match_message_2[] = {
- /* EXAMPLE_NAME is in all of these namespaces */
- "arg0namespace='com.example.backend'",
- "arg0namespace='com.example'",
- "arg0namespace='com'",
-
- /* If the client specifies the name exactly, with no trailing period, then
- * it should match.
- */
- "arg0namespace='com.example.backend.foo'",
-
- NULL
-};
-
-static const char *
-should_not_match_message_2[] = {
- /* These are not even prefixes */
- "arg0namespace='com.example.backend.foo.bar'",
- "arg0namespace='com.example.backend.foobar'",
-
- /* These are prefixes, but they're not parent namespaces. */
- "arg0namespace='com.example.backend.fo'",
- "arg0namespace='com.example.backen'",
- "arg0namespace='com.exampl'",
- "arg0namespace='co'",
-
NULL
};
@@ -2587,7 +2276,7 @@ check_matching (DBusMessage *message,
static void
test_matching (void)
{
- DBusMessage *message1, *message2;
+ DBusMessage *message1;
const char *v_STRING;
dbus_int32_t v_INT32;
@@ -2609,185 +2298,6 @@ test_matching (void)
should_not_match_message_1);
dbus_message_unref (message1);
-
- message2 = dbus_message_new (DBUS_MESSAGE_TYPE_SIGNAL);
- _dbus_assert (message2 != NULL);
- if (!dbus_message_set_member (message2, "NameOwnerChanged"))
- _dbus_assert_not_reached ("oom");
-
- /* Obviously this isn't really a NameOwnerChanged signal. */
- v_STRING = EXAMPLE_NAME;
- if (!dbus_message_append_args (message2,
- DBUS_TYPE_STRING, &v_STRING,
- NULL))
- _dbus_assert_not_reached ("oom");
-
- check_matching (message2, 2,
- should_match_message_2,
- should_not_match_message_2);
-
- dbus_message_unref (message2);
-}
-
-#define PATH_MATCH_RULE "arg0path='/aa/bb/'"
-
-/* This is a list of paths that should be matched by PATH_MATCH_RULE, taken
- * from the specification. Notice that not all of them are actually legal D-Bus
- * paths.
- *
- * The author of this test takes no responsibility for the semantics of
- * this match rule key.
- */
-static const char *paths_that_should_be_matched[] = {
- "/aa/",
- "/aa/bb/",
- "/aa/bb/cc/",
-#define FIRST_VALID_PATH_WHICH_SHOULD_MATCH 3
- "/",
- "/aa/bb/cc",
- NULL
-};
-
-/* These paths should not be matched by PATH_MATCH_RULE. */
-static const char *paths_that_should_not_be_matched[] = {
- "/aa/b",
- "/aa",
- /* or even... */
- "/aa/bb",
- NULL
-};
-
-static void
-test_path_match (int type,
- const char *path,
- const char *rule_text,
- BusMatchRule *rule,
- dbus_bool_t should_match)
-{
- DBusMessage *message = dbus_message_new (DBUS_MESSAGE_TYPE_SIGNAL);
- dbus_bool_t matched;
-
- _dbus_assert (message != NULL);
- if (!dbus_message_set_member (message, "Foo"))
- _dbus_assert_not_reached ("oom");
-
- if (!dbus_message_append_args (message,
- type, &path,
- NULL))
- _dbus_assert_not_reached ("oom");
-
- matched = match_rule_matches (rule, NULL, NULL, message, 0);
-
- if (matched != should_match)
- {
- _dbus_warn ("Expected rule %s to %s message "
- "with first arg %s of type '%c', failed\n",
- rule_text,
- should_match ? "match" : "not match",
- path,
- (char) type);
- exit (1);
- }
-
- dbus_message_unref (message);
-}
-
-static void
-test_path_matching (void)
-{
- BusMatchRule *rule;
- const char **s;
-
- rule = check_parse (TRUE, PATH_MATCH_RULE);
- _dbus_assert (rule != NULL);
-
- for (s = paths_that_should_be_matched; *s != NULL; s++)
- test_path_match (DBUS_TYPE_STRING, *s, PATH_MATCH_RULE, rule, TRUE);
-
- for (s = paths_that_should_be_matched + FIRST_VALID_PATH_WHICH_SHOULD_MATCH;
- *s != NULL; s++)
- test_path_match (DBUS_TYPE_OBJECT_PATH, *s, PATH_MATCH_RULE, rule, TRUE);
-
- for (s = paths_that_should_not_be_matched; *s != NULL; s++)
- {
- test_path_match (DBUS_TYPE_STRING, *s, PATH_MATCH_RULE, rule, FALSE);
- test_path_match (DBUS_TYPE_OBJECT_PATH, *s, PATH_MATCH_RULE, rule, FALSE);
- }
-
- bus_match_rule_unref (rule);
-}
-
-static const char*
-path_namespace_should_match_message_1[] = {
- "type='signal',path_namespace='/foo'",
- "type='signal',path_namespace='/foo/TheObjectManager'",
- NULL
-};
-
-static const char*
-path_namespace_should_not_match_message_1[] = {
- "type='signal',path_namespace='/bar'",
- "type='signal',path_namespace='/bar/TheObjectManager'",
- NULL
-};
-
-static const char*
-path_namespace_should_match_message_2[] = {
- "type='signal',path_namespace='/foo/TheObjectManager'",
- NULL
-};
-
-static const char*
-path_namespace_should_not_match_message_2[] = {
- NULL
-};
-
-static const char*
-path_namespace_should_match_message_3[] = {
- NULL
-};
-
-static const char*
-path_namespace_should_not_match_message_3[] = {
- "type='signal',path_namespace='/foo/TheObjectManager'",
- NULL
-};
-
-static void
-test_matching_path_namespace (void)
-{
- DBusMessage *message1;
- DBusMessage *message2;
- DBusMessage *message3;
-
- message1 = dbus_message_new (DBUS_MESSAGE_TYPE_SIGNAL);
- _dbus_assert (message1 != NULL);
- if (!dbus_message_set_path (message1, "/foo/TheObjectManager"))
- _dbus_assert_not_reached ("oom");
-
- message2 = dbus_message_new (DBUS_MESSAGE_TYPE_SIGNAL);
- _dbus_assert (message2 != NULL);
- if (!dbus_message_set_path (message2, "/foo/TheObjectManager/child_object"))
- _dbus_assert_not_reached ("oom");
-
- message3 = dbus_message_new (DBUS_MESSAGE_TYPE_SIGNAL);
- _dbus_assert (message3 != NULL);
- if (!dbus_message_set_path (message3, "/foo/TheObjectManagerOther"))
- _dbus_assert_not_reached ("oom");
-
- check_matching (message1, 1,
- path_namespace_should_match_message_1,
- path_namespace_should_not_match_message_1);
- check_matching (message2, 2,
- path_namespace_should_match_message_2,
- path_namespace_should_not_match_message_2);
- check_matching (message3, 3,
- path_namespace_should_match_message_3,
- path_namespace_should_not_match_message_3);
-
- dbus_message_unref (message3);
- dbus_message_unref (message2);
- dbus_message_unref (message1);
}
dbus_bool_t
@@ -2804,10 +2314,9 @@ bus_signals_test (const DBusString *test_data_dir)
_dbus_assert_not_reached ("Parsing match rules test failed");
test_equality ();
- test_matching ();
- test_path_matching ();
- test_matching_path_namespace ();
+ test_matching ();
+
return TRUE;
}
diff --git a/bus/signals.h b/bus/signals.h
index a71d2e45..eeb1d2d0 100644
--- a/bus/signals.h
+++ b/bus/signals.h
@@ -31,15 +31,13 @@
typedef enum
{
- BUS_MATCH_MESSAGE_TYPE = 1 << 0,
- BUS_MATCH_INTERFACE = 1 << 1,
- BUS_MATCH_MEMBER = 1 << 2,
- BUS_MATCH_SENDER = 1 << 3,
- BUS_MATCH_DESTINATION = 1 << 4,
- BUS_MATCH_PATH = 1 << 5,
- BUS_MATCH_ARGS = 1 << 6,
- BUS_MATCH_PATH_NAMESPACE = 1 << 7,
- BUS_MATCH_CLIENT_IS_EAVESDROPPING = 1 << 8
+ BUS_MATCH_MESSAGE_TYPE = 1 << 0,
+ BUS_MATCH_INTERFACE = 1 << 1,
+ BUS_MATCH_MEMBER = 1 << 2,
+ BUS_MATCH_SENDER = 1 << 3,
+ BUS_MATCH_DESTINATION = 1 << 4,
+ BUS_MATCH_PATH = 1 << 5,
+ BUS_MATCH_ARGS = 1 << 6
} BusMatchFlags;
BusMatchRule* bus_match_rule_new (DBusConnection *matches_go_to);
@@ -57,21 +55,11 @@ dbus_bool_t bus_match_rule_set_sender (BusMatchRule *rule,
dbus_bool_t bus_match_rule_set_destination (BusMatchRule *rule,
const char *destination);
dbus_bool_t bus_match_rule_set_path (BusMatchRule *rule,
- const char *path,
- dbus_bool_t is_namespace);
+ const char *path);
dbus_bool_t bus_match_rule_set_arg (BusMatchRule *rule,
int arg,
const DBusString *value,
- dbus_bool_t is_path,
- dbus_bool_t is_namespace);
-
-/* Calling this methods a client declares that it is creating a rule which
- * needs to eavesdrop (e.g., dbus-monitor), any other created rules not
- * setting themselves as eavesdropping won't receive any message not addressed
- * to them, when eavedrop is enabled in the policy. On the other hand, when
- * eavedrop is not enabled in policy, this method won't have any effect */
-void bus_match_rule_set_client_is_eavesdropping (BusMatchRule *rule,
- dbus_bool_t is_eavesdropping);
+ dbus_bool_t is_path);
BusMatchRule* bus_match_rule_parse (DBusConnection *matches_go_to,
const DBusString *rule_text,
diff --git a/bus/test-main.c b/bus/test-main.c
index 1b7c5bea..a8039d51 100644
--- a/bus/test-main.c
+++ b/bus/test-main.c
@@ -130,6 +130,15 @@ main (int argc, char **argv)
test_post_hook ();
}
+ if (only == NULL || strcmp (only, "policy") == 0)
+ {
+ test_pre_hook ();
+ printf ("%s: Running policy test\n", argv[0]);
+ if (!bus_policy_test (&test_data_dir))
+ die ("policy");
+ test_post_hook ();
+ }
+
if (only == NULL || strcmp (only, "signals") == 0)
{
test_pre_hook ();
diff --git a/bus/test.c b/bus/test.c
index e1b8a130..6efad6e0 100644
--- a/bus/test.c
+++ b/bus/test.c
@@ -37,31 +37,69 @@ static DBusList *clients = NULL;
static DBusLoop *client_loop = NULL;
static dbus_bool_t
+client_watch_callback (DBusWatch *watch,
+ unsigned int condition,
+ void *data)
+{
+ /* FIXME this can be done in dbus-mainloop.c
+ * if the code in activation.c for the babysitter
+ * watch handler is fixed.
+ */
+
+ return dbus_watch_handle (watch, condition);
+}
+
+static dbus_bool_t
add_client_watch (DBusWatch *watch,
void *data)
{
- return _dbus_loop_add_watch (client_loop, watch);
+ DBusConnection *connection = data;
+
+ return _dbus_loop_add_watch (client_loop,
+ watch, client_watch_callback, connection,
+ NULL);
}
static void
remove_client_watch (DBusWatch *watch,
void *data)
{
- _dbus_loop_remove_watch (client_loop, watch);
+ DBusConnection *connection = data;
+
+ _dbus_loop_remove_watch (client_loop,
+ watch, client_watch_callback, connection);
+}
+
+static void
+client_timeout_callback (DBusTimeout *timeout,
+ void *data)
+{
+ DBusConnection *connection = data;
+
+ dbus_connection_ref (connection);
+
+ /* can return FALSE on OOM but we just let it fire again later */
+ dbus_timeout_handle (timeout);
+
+ dbus_connection_unref (connection);
}
static dbus_bool_t
add_client_timeout (DBusTimeout *timeout,
void *data)
{
- return _dbus_loop_add_timeout (client_loop, timeout);
+ DBusConnection *connection = data;
+
+ return _dbus_loop_add_timeout (client_loop, timeout, client_timeout_callback, connection, NULL);
}
static void
remove_client_timeout (DBusTimeout *timeout,
void *data)
{
- _dbus_loop_remove_timeout (client_loop, timeout);
+ DBusConnection *connection = data;
+
+ _dbus_loop_remove_timeout (client_loop, timeout, client_timeout_callback, connection);
}
static DBusHandlerResult
diff --git a/bus/test.h b/bus/test.h
index 98a2c6ba..45024e65 100644
--- a/bus/test.h
+++ b/bus/test.h
@@ -32,6 +32,7 @@
dbus_bool_t bus_dispatch_test (const DBusString *test_data_dir);
dbus_bool_t bus_dispatch_sha1_test (const DBusString *test_data_dir);
+dbus_bool_t bus_policy_test (const DBusString *test_data_dir);
dbus_bool_t bus_config_parser_test (const DBusString *test_data_dir);
dbus_bool_t bus_config_parser_trivial_test (const DBusString *test_data_dir);
dbus_bool_t bus_signals_test (const DBusString *test_data_dir);