]> git.ipfire.org Git - thirdparty/dbus.git/commitdiff
DBusMessage: Add a header field for the container instance
authorSimon McVittie <smcv@collabora.com>
Mon, 15 Jan 2018 16:30:33 +0000 (16:30 +0000)
committerSimon McVittie <smcv@collabora.com>
Fri, 16 Feb 2018 15:27:37 +0000 (15:27 +0000)
In the bus daemon, don't pass through the container instance path:
if there's any value here at all, we want to be able to guarantee that
we sent it (in a later commit).

Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=101899

bus/dispatch.c
dbus/dbus-marshal-header.c
dbus/dbus-message-util.c
dbus/dbus-message.c
dbus/dbus-message.h
dbus/dbus-protocol.h

index b16ad2b3a095e44dd4f257d821f8f9692ddc8007..c3914a86e7d1778e0ae30b8e3a86df2ffa931f4f 100644 (file)
@@ -290,7 +290,8 @@ bus_dispatch (DBusConnection *connection,
   /* Make sure the message does not have any header fields that we
    * don't understand (or validate), so that we can add header fields
    * in future and clients can assume that we have checked them. */
-  if (!_dbus_message_remove_unknown_fields (message))
+  if (!_dbus_message_remove_unknown_fields (message) ||
+      !dbus_message_set_container_instance (message, NULL))
     {
       BUS_SET_OOM (&error);
       goto out;
index f9a3325838399e40b07d1e76bc1d34f8b1e3db46..b2461749cf1e6c68c49dfac7a93affee03ecb840 100644 (file)
@@ -83,7 +83,8 @@ _dbus_header_field_types[DBUS_HEADER_FIELD_LAST+1] = {
   { DBUS_HEADER_FIELD_DESTINATION, DBUS_TYPE_STRING },
   { DBUS_HEADER_FIELD_SENDER, DBUS_TYPE_STRING },
   { DBUS_HEADER_FIELD_SIGNATURE, DBUS_TYPE_SIGNATURE },
-  { DBUS_HEADER_FIELD_UNIX_FDS, DBUS_TYPE_UINT32 }
+  { DBUS_HEADER_FIELD_UNIX_FDS, DBUS_TYPE_UINT32 },
+  { DBUS_HEADER_FIELD_CONTAINER_INSTANCE, DBUS_TYPE_OBJECT_PATH }
 };
 
 /** Macro to look up the correct type for a field */
@@ -919,6 +920,11 @@ load_and_validate_field (DBusHeader     *header,
       string_validation_func = NULL;
       break;
 
+    case DBUS_HEADER_FIELD_CONTAINER_INSTANCE:
+      /* OBJECT_PATH was validated generically due to its type */
+      string_validation_func = NULL;
+      break;
+
     default:
       _dbus_assert_not_reached ("unknown field shouldn't be seen here");
       break;
index 2fefbe4f86e09bf86482925ba705798a9dfd2333..6b4acf6074bd109aa04e94d78e44951d6a4d81fb 100644 (file)
@@ -1294,6 +1294,11 @@ _dbus_message_test (const char *test_data_dir)
   _dbus_assert (strcmp (dbus_message_get_path (message),
                         "/foo") == 0);
 
+  if (!dbus_message_set_container_instance (message, "/org/freedesktop/DBus/Containers1/c42"))
+    _dbus_test_fatal ("out of memory");
+  _dbus_assert (strcmp (dbus_message_get_container_instance (message),
+                        "/org/freedesktop/DBus/Containers1/c42") == 0);
+
   if (!dbus_message_set_interface (message, "org.Foo"))
     _dbus_test_fatal ("out of memory");
   _dbus_assert (strcmp (dbus_message_get_interface (message),
index 36066848098d3edad39d47ac1b1bbce9d57de238..d9e5bb905d49767a561015709a0066cd22641b53 100644 (file)
@@ -4069,6 +4069,57 @@ dbus_message_contains_unix_fds(DBusMessage *message)
 #endif
 }
 
+/**
+ * Sets the container instance this message was sent from.
+ *
+ * The path must contain only valid characters for an object path
+ * as defined in the D-Bus specification.
+ *
+ * @param message the message
+ * @param object_path the path or #NULL to unset
+ * @returns #FALSE if not enough memory
+ */
+dbus_bool_t
+dbus_message_set_container_instance (DBusMessage   *message,
+                                     const char    *object_path)
+{
+  _dbus_return_val_if_fail (message != NULL, FALSE);
+  _dbus_return_val_if_fail (!message->locked, FALSE);
+  _dbus_return_val_if_fail (object_path == NULL ||
+                            _dbus_check_is_valid_path (object_path),
+                            FALSE);
+
+  return set_or_delete_string_field (message,
+                                     DBUS_HEADER_FIELD_CONTAINER_INSTANCE,
+                                     DBUS_TYPE_OBJECT_PATH,
+                                     object_path);
+}
+
+/**
+ * Gets the container instance this message was sent from, or #NULL
+ * if none.
+ *
+ * The returned string becomes invalid if the message is
+ * modified, since it points into the wire-marshaled message data.
+ *
+ * @param message the message
+ * @returns the path (should not be freed) or #NULL
+ */
+const char *
+dbus_message_get_container_instance (DBusMessage *message)
+{
+  const char *v;
+
+  _dbus_return_val_if_fail (message != NULL, NULL);
+
+  v = NULL; /* in case field doesn't exist */
+  _dbus_header_get_field_basic (&message->header,
+                                DBUS_HEADER_FIELD_CONTAINER_INSTANCE,
+                                DBUS_TYPE_OBJECT_PATH,
+                                (void *) &v);
+  return v;
+}
+
 /** @} */
 
 /**
index 8a9d57a0f1ea46aa2976b849dc174a7daffeb91e..9d590ceb1f333df3b5a0a120cb850d5b4de9b0da 100644 (file)
@@ -217,6 +217,12 @@ DBUS_EXPORT
 dbus_bool_t   dbus_message_get_path_decomposed (DBusMessage   *message,
                                                 char        ***path);
 
+DBUS_EXPORT
+const char   *dbus_message_get_container_instance (DBusMessage   *message);
+DBUS_EXPORT
+dbus_bool_t   dbus_message_set_container_instance (DBusMessage   *message,
+                                                   const char    *object_path);
+
 DBUS_EXPORT
 dbus_bool_t dbus_message_append_args          (DBusMessage     *message,
                                               int              first_arg_type,
index 56be98328e80c6f69935ede1ea8f673832c50137..61f6212d40e096b03c161bc91a932cee064eff13 100644 (file)
@@ -300,6 +300,10 @@ extern "C" {
  * with this message.
  */
 #define DBUS_HEADER_FIELD_UNIX_FDS       9
+/**
+ * Header field code for the container instance that sent this message.
+ */
+#define DBUS_HEADER_FIELD_CONTAINER_INSTANCE 10
 
 
 /**
@@ -308,7 +312,7 @@ extern "C" {
  * that unknown codes must be ignored, so check for that before
  * indexing the array.
  */
-#define DBUS_HEADER_FIELD_LAST DBUS_HEADER_FIELD_UNIX_FDS
+#define DBUS_HEADER_FIELD_LAST DBUS_HEADER_FIELD_CONTAINER_INSTANCE
 
 /** Header format is defined as a signature:
  *   byte                            byte order