summaryrefslogtreecommitdiffstats
path: root/dbus
diff options
context:
space:
mode:
Diffstat (limited to 'dbus')
-rw-r--r--dbus/dbus-bus.c47
-rw-r--r--dbus/dbus-glib-lowlevel.h7
-rw-r--r--dbus/dbus-shared.h5
-rw-r--r--dbus/dbus-sysdeps.c55
4 files changed, 84 insertions, 30 deletions
diff --git a/dbus/dbus-bus.c b/dbus/dbus-bus.c
index 9016f1b1..7578efb2 100644
--- a/dbus/dbus-bus.c
+++ b/dbus/dbus-bus.c
@@ -655,20 +655,17 @@ dbus_bus_get_unix_user (DBusConnection *connection,
* result codes are discussed here, but the specification is the
* canonical version of this information.
*
- * The #DBUS_NAME_FLAG_PROHIBIT_REPLACEMENT flag indicates that
- * if the name is successfully requested, other applications
- * will not be able to take over the name. i.e. the name's
- * owner (the application calling this function) must let go of
- * the name, it will not lose it involuntarily.
+ * The #DBUS_NAME_FLAG_ALLOW_REPLACEMENT flag indicates that the caller
+ * will allow other services to take over the name from the current owner.
*
* The #DBUS_NAME_FLAG_REPLACE_EXISTING flag indicates that the caller
* would like to take over the name from the current owner.
- * If the current name owner used #DBUS_NAME_FLAG_PROHIBIT_REPLACEMENT
+ * If the current name owner did not use #DBUS_NAME_FLAG_ALLOW_REPLACEMENT
* then this flag indicates that the caller would like to be placed
* in the queue to own the name when the current owner lets go.
*
* If no flags are given, an application will receive the requested
- * name only if the name is currently unowned; and it will give
+ * name only if the name is currently unowned; it will NOT give
* up the name if another application asks to take it over using
* #DBUS_NAME_FLAG_REPLACE_EXISTING.
*
@@ -678,27 +675,31 @@ dbus_bus_get_unix_user (DBusConnection *connection,
* #DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER means that the name had no
* existing owner, and the caller is now the primary owner; or that
* the name had an owner, and the caller specified
- * #DBUS_NAME_FLAG_REPLACE_EXISTING, and the current owner did not
- * specify #DBUS_NAME_FLAG_PROHIBIT_REPLACEMENT.
+ * #DBUS_NAME_FLAG_REPLACE_EXISTING, and the current owner
+ * specified #DBUS_NAME_FLAG_ALLOW_REPLACEMENT.
*
- * #DBUS_REQUEST_NAME_REPLY_IN_QUEUE happens only if the current owner
- * specified #DBUS_NAME_FLAG_PROHIBIT_REPLACEMENT and the caller specified
- * #DBUS_NAME_FLAG_REPLACE_EXISTING. In this case the caller ends up in
- * a queue to own the name after the current owner gives it up.
+ * #DBUS_REQUEST_NAME_REPLY_IN_QUEUE happens only if the caller does NOT
+ * specify #DBUS_NAME_FLAG_DO_NOT_QUEUE and either the current owner
+ * did NOT specify #DBUS_NAME_FLAG_ALLOW_REPLACEMENT or the caller did NOT
+ * specify #DBUS_NAME_FLAG_REPLACE_EXISTING. In this case the caller ends up
+ * in a queue to own the name after the current owner gives it up.
*
* #DBUS_REQUEST_NAME_REPLY_EXISTS happens if the name has an owner
- * #already and DBUS_NAME_FLAG_REPLACE_EXISTING was not specified.
+ * already and the caller specifies #DBUS_NAME_FLAG_DO_NOT_QUEUE
+ * and either the current owner has NOT specified
+ * #DBUS_NAME_FLAG_ALLOW_REPLACEMENT or the caller did NOT specify
+ * #DBUS_NAME_FLAG_REPLACE_EXISTING.
*
* #DBUS_REQUEST_NAME_REPLY_ALREADY_OWNER happens if an application
* requests a name it already owns.
*
* When a service represents an application, say "text editor," then
- * it should specify #DBUS_NAME_FLAG_PROHIBIT_REPLACEMENT if it wants
- * the first editor started to be the user's editor vs. the last one
+ * it should specify #DBUS_NAME_FLAG_ALLOW_REPLACEMENT if it wants
+ * the last editor started to be the user's editor vs. the first one
* started. Then any editor that can be the user's editor should
* specify #DBUS_NAME_FLAG_REPLACE_EXISTING to either take over
* (last-started-wins) or be queued up (first-started-wins) according
- * to whether #DBUS_NAME_FLAG_PROHIBIT_REPLACEMENT was given.
+ * to whether #DBUS_NAME_FLAG_ALLOW_REPLACEMENT was given.
*
* @todo this all seems sort of broken. Shouldn't the flags be a property
* of the name, not the app requesting the name? What are the use-cases
@@ -1097,4 +1098,16 @@ dbus_bus_remove_match (DBusConnection *connection,
dbus_message_unref (msg);
}
+#ifdef DBUS_BUILD_TESTS
+const char *
+dbus_bus_connection_get_unique_name (DBusConnection *connection)
+{
+ BusData *bd;
+ bd = dbus_connection_get_data (connection, bus_data_slot);
+
+ return bd->unique_name;
+}
+#endif /* DBUS_BUILD_TESTS */
+
+
/** @} */
diff --git a/dbus/dbus-glib-lowlevel.h b/dbus/dbus-glib-lowlevel.h
index 9f6fc84e..cb015ccb 100644
--- a/dbus/dbus-glib-lowlevel.h
+++ b/dbus/dbus-glib-lowlevel.h
@@ -57,9 +57,12 @@ DBusMessage* dbus_g_message_get_message (DBusGMessage *gmessage);
* g-functions anyhow)
*/
-DBusMessage * dbus_g_method_return_get_reply (DBusGMethodInvocation *context);
+gchar* dbus_g_method_get_sender (DBusGMethodInvocation *context);
-void dbus_g_method_return_send_reply (DBusGMethodInvocation *context, DBusMessage *reply);
+DBusMessage* dbus_g_method_get_reply (DBusGMethodInvocation *context);
+
+void dbus_g_method_send_reply (DBusGMethodInvocation *context,
+ DBusMessage *reply);
G_END_DECLS
diff --git a/dbus/dbus-shared.h b/dbus/dbus-shared.h
index a8519c13..2ef1dc9c 100644
--- a/dbus/dbus-shared.h
+++ b/dbus/dbus-shared.h
@@ -68,8 +68,9 @@ typedef enum
#define DBUS_INTERFACE_LOCAL "org.freedesktop.DBus.Local"
/* Owner flags */
-#define DBUS_NAME_FLAG_PROHIBIT_REPLACEMENT 0x1
-#define DBUS_NAME_FLAG_REPLACE_EXISTING 0x2
+#define DBUS_NAME_FLAG_ALLOW_REPLACEMENT 0x1
+#define DBUS_NAME_FLAG_REPLACE_EXISTING 0x2
+#define DBUS_NAME_FLAG_DO_NOT_QUEUE 0x4
/* Replies to request for a name */
#define DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER 1
diff --git a/dbus/dbus-sysdeps.c b/dbus/dbus-sysdeps.c
index 1b7cd906..030d0801 100644
--- a/dbus/dbus-sysdeps.c
+++ b/dbus/dbus-sysdeps.c
@@ -398,6 +398,7 @@ _dbus_connect_unix_socket (const char *path,
DBusError *error)
{
int fd;
+ size_t path_len;
struct sockaddr_un addr;
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
@@ -419,15 +420,23 @@ _dbus_connect_unix_socket (const char *path,
_DBUS_ZERO (addr);
addr.sun_family = AF_UNIX;
+ path_len = strlen (path);
if (abstract)
{
#ifdef HAVE_ABSTRACT_SOCKETS
- /* remember that abstract names aren't nul-terminated so we rely
- * on sun_path being filled in with zeroes above.
- */
addr.sun_path[0] = '\0'; /* this is what says "use abstract" */
- strncpy (&addr.sun_path[1], path, _DBUS_MAX_SUN_PATH_LENGTH - 2);
+ path_len++; /* Account for the extra nul byte added to the start of sun_path */
+
+ if (path_len > _DBUS_MAX_SUN_PATH_LENGTH)
+ {
+ dbus_set_error (error, DBUS_ERROR_BAD_ADDRESS,
+ "Abstract socket name too long\n");
+ close (fd);
+ return -1;
+ }
+
+ strncpy (&addr.sun_path[1], path, path_len);
/* _dbus_verbose_bytes (addr.sun_path, sizeof (addr.sun_path)); */
#else /* HAVE_ABSTRACT_SOCKETS */
dbus_set_error (error, DBUS_ERROR_NOT_SUPPORTED,
@@ -438,10 +447,18 @@ _dbus_connect_unix_socket (const char *path,
}
else
{
- strncpy (addr.sun_path, path, _DBUS_MAX_SUN_PATH_LENGTH - 1);
+ if (path_len > _DBUS_MAX_SUN_PATH_LENGTH)
+ {
+ dbus_set_error (error, DBUS_ERROR_BAD_ADDRESS,
+ "Socket name too long\n");
+ close (fd);
+ return -1;
+ }
+
+ strncpy (addr.sun_path, path, path_len);
}
- if (connect (fd, (struct sockaddr*) &addr, sizeof (addr)) < 0)
+ if (connect (fd, (struct sockaddr*) &addr, _DBUS_STRUCT_OFFSET (struct sockaddr_un, sun_path) + path_len) < 0)
{
dbus_set_error (error,
_dbus_error_from_errno (errno),
@@ -489,6 +506,7 @@ _dbus_listen_unix_socket (const char *path,
{
int listen_fd;
struct sockaddr_un addr;
+ size_t path_len;
_DBUS_ASSERT_ERROR_IS_CLEAR (error);
@@ -507,6 +525,7 @@ _dbus_listen_unix_socket (const char *path,
_DBUS_ZERO (addr);
addr.sun_family = AF_UNIX;
+ path_len = strlen (path);
if (abstract)
{
@@ -515,7 +534,17 @@ _dbus_listen_unix_socket (const char *path,
* on sun_path being filled in with zeroes above.
*/
addr.sun_path[0] = '\0'; /* this is what says "use abstract" */
- strncpy (&addr.sun_path[1], path, _DBUS_MAX_SUN_PATH_LENGTH - 2);
+ path_len++; /* Account for the extra nul byte added to the start of sun_path */
+
+ if (path_len > _DBUS_MAX_SUN_PATH_LENGTH)
+ {
+ dbus_set_error (error, DBUS_ERROR_BAD_ADDRESS,
+ "Abstract socket name too long\n");
+ close (listen_fd);
+ return -1;
+ }
+
+ strncpy (&addr.sun_path[1], path, path_len);
/* _dbus_verbose_bytes (addr.sun_path, sizeof (addr.sun_path)); */
#else /* HAVE_ABSTRACT_SOCKETS */
dbus_set_error (error, DBUS_ERROR_NOT_SUPPORTED,
@@ -544,10 +573,18 @@ _dbus_listen_unix_socket (const char *path,
unlink (path);
}
- strncpy (addr.sun_path, path, _DBUS_MAX_SUN_PATH_LENGTH - 1);
+ if (path_len > _DBUS_MAX_SUN_PATH_LENGTH)
+ {
+ dbus_set_error (error, DBUS_ERROR_BAD_ADDRESS,
+ "Abstract socket name too long\n");
+ close (listen_fd);
+ return -1;
+ }
+
+ strncpy (addr.sun_path, path, path_len);
}
- if (bind (listen_fd, (struct sockaddr*) &addr, sizeof (addr)) < 0)
+ if (bind (listen_fd, (struct sockaddr*) &addr, _DBUS_STRUCT_OFFSET (struct sockaddr_un, sun_path) + path_len) < 0)
{
dbus_set_error (error, _dbus_error_from_errno (errno),
"Failed to bind socket \"%s\": %s",