* configure.in: Add test/name-test/Makefile to the generated
[platform/upstream/dbus.git] / bus / driver.c
index 8e8a536..10f37bd 100644 (file)
@@ -308,12 +308,10 @@ bus_driver_handle_hello (DBusConnection *connection,
 
   /* Create the service */
   service = bus_registry_ensure (registry,
-                                 &unique_name, connection, transaction, error);
+                                 &unique_name, connection, 0, transaction, error);
   if (service == NULL)
     goto out_0;
   
-  bus_service_set_prohibit_replacement (service, TRUE);
-
   _dbus_assert (bus_connection_is_active (connection));
   retval = TRUE;
   
@@ -470,7 +468,7 @@ bus_driver_handle_acquire_service (DBusConnection *connection,
   DBusMessage *reply;
   DBusString service_name;
   const char *name;
-  int service_reply;
+  dbus_uint32_t service_reply;
   dbus_uint32_t flags;
   dbus_bool_t retval;
   BusRegistry *registry;
@@ -526,6 +524,67 @@ bus_driver_handle_acquire_service (DBusConnection *connection,
 } 
 
 static dbus_bool_t
+bus_driver_handle_release_service (DBusConnection *connection,
+                                   BusTransaction *transaction,
+                                   DBusMessage    *message,
+                                   DBusError      *error)
+{
+  DBusMessage *reply;
+  DBusString service_name;
+  const char *name;
+  dbus_uint32_t service_reply;
+  dbus_bool_t retval;
+  BusRegistry *registry;
+
+  _DBUS_ASSERT_ERROR_IS_CLEAR (error);
+
+  registry = bus_connection_get_registry (connection);
+
+  if (!dbus_message_get_args (message, error,
+                              DBUS_TYPE_STRING, &name,
+                              DBUS_TYPE_INVALID))
+    return FALSE;
+
+  _dbus_verbose ("Trying to release name %s\n", name);
+
+  retval = FALSE;
+  reply = NULL;
+
+  _dbus_string_init_const (&service_name, name);
+
+  if (!bus_registry_release_service (registry, connection,
+                                     &service_name, &service_reply,
+                                     transaction, error))
+    goto out;
+
+  reply = dbus_message_new_method_return (message);
+  if (reply == NULL)
+    {
+      BUS_SET_OOM (error);
+      goto out;
+    }
+
+  if (!dbus_message_append_args (reply, DBUS_TYPE_UINT32, &service_reply, DBUS_TYPE_INVALID))
+    {
+      BUS_SET_OOM (error);
+      goto out;
+    }
+
+  if (!bus_transaction_send_from_driver (transaction, connection, reply))
+    {
+      BUS_SET_OOM (error);
+      goto out;
+    }
+
+  retval = TRUE;
+
+ out:
+  if (reply)
+    dbus_message_unref (reply);
+  return retval;
+}
+
+static dbus_bool_t
 bus_driver_handle_service_exists (DBusConnection *connection,
                                   BusTransaction *transaction,
                                   DBusMessage    *message,
@@ -822,7 +881,7 @@ bus_driver_handle_get_service_owner (DBusConnection *connection,
     }
   else
     {
-      base_name = bus_connection_get_name (bus_service_get_primary_owner (service));
+      base_name = bus_connection_get_name (bus_service_get_primary_owners_connection (service));
       if (base_name == NULL)
         {
           /* FIXME - how is this error possible? */
@@ -863,6 +922,113 @@ bus_driver_handle_get_service_owner (DBusConnection *connection,
 }
 
 static dbus_bool_t
+bus_driver_handle_list_queued_owners (DBusConnection *connection,
+                                     BusTransaction *transaction,
+                                     DBusMessage    *message,
+                                     DBusError      *error)
+{
+  const char *text;
+  DBusList *base_names;
+  DBusList *link;
+  DBusString str;
+  BusRegistry *registry;
+  BusService *service;
+  DBusMessage *reply;
+  DBusMessageIter iter, array_iter;
+  char *dbus_service_name = DBUS_SERVICE_DBUS;
+  
+  _DBUS_ASSERT_ERROR_IS_CLEAR (error);
+
+  registry = bus_connection_get_registry (connection);
+
+  base_names = NULL;
+  text = NULL;
+  reply = NULL;
+
+  if (! dbus_message_get_args (message, error,
+                              DBUS_TYPE_STRING, &text,
+                              DBUS_TYPE_INVALID))
+      goto failed;
+
+  _dbus_string_init_const (&str, text);
+  service = bus_registry_lookup (registry, &str);
+  if (service == NULL &&
+      _dbus_string_equal_c_str (&str, DBUS_SERVICE_DBUS))
+    {
+      /* ORG_FREEDESKTOP_DBUS owns itself */
+      if (! _dbus_list_append (&base_names, dbus_service_name))
+        goto oom;
+    }
+  else if (service == NULL)
+    {
+      dbus_set_error (error, 
+                      DBUS_ERROR_NAME_HAS_NO_OWNER,
+                      "Could not get owners of name '%s': no such name", text);
+      goto failed;
+    }
+  else
+    {
+      if (!bus_service_list_queued_owners (service, 
+                                           &base_names,
+                                           error))
+        goto failed;
+    }
+
+  _dbus_assert (base_names != NULL);
+
+  reply = dbus_message_new_method_return (message);
+  if (reply == NULL)
+    goto oom;
+
+  dbus_message_iter_init_append (reply, &iter);
+  if (!dbus_message_iter_open_container (&iter,
+                                         DBUS_TYPE_ARRAY,
+                                         DBUS_TYPE_STRING_AS_STRING,
+                                         &array_iter))
+    goto oom;
+  
+  link = _dbus_list_get_first_link (&base_names);
+  while (link != NULL)
+    {
+      char *uname;
+
+      _dbus_assert (link->data != NULL);
+      uname = (char *)link->data;
+    
+      if (!dbus_message_iter_append_basic (&array_iter, 
+                                           DBUS_TYPE_STRING,
+                                           &uname))
+        goto oom;
+
+      link = _dbus_list_get_next_link (&base_names, link);
+    }
+
+  if (! dbus_message_iter_close_container (&iter, &array_iter))
+    goto oom;
+                                    
+  if (! bus_transaction_send_from_driver (transaction, connection, reply))
+    goto oom;
+
+  dbus_message_unref (reply);
+
+  return TRUE;
+
+ oom:
+  BUS_SET_OOM (error);
+
+ failed:
+  _DBUS_ASSERT_ERROR_IS_SET (error);
+  if (reply)
+    dbus_message_unref (reply);
+
+  if (base_names)
+    _dbus_list_clear (&base_names);
+
+  return FALSE;
+}
+
+static dbus_bool_t
 bus_driver_handle_get_connection_unix_user (DBusConnection *connection,
                                             BusTransaction *transaction,
                                             DBusMessage    *message,
@@ -901,7 +1067,7 @@ bus_driver_handle_get_connection_unix_user (DBusConnection *connection,
       goto failed;
     }
 
-  conn = bus_service_get_primary_owner (serv);
+  conn = bus_service_get_primary_owners_connection (serv);
 
   reply = dbus_message_new_method_return (message);
   if (reply == NULL)
@@ -977,7 +1143,7 @@ bus_driver_handle_get_connection_unix_process_id (DBusConnection *connection,
       goto failed;
     }
 
-  conn = bus_service_get_primary_owner (serv);
+  conn = bus_service_get_primary_owners_connection (serv);
 
   reply = dbus_message_new_method_return (message);
   if (reply == NULL)
@@ -1015,10 +1181,10 @@ bus_driver_handle_get_connection_unix_process_id (DBusConnection *connection,
 }
 
 static dbus_bool_t
-bus_driver_handle_get_connection_unix_security_context (DBusConnection *connection,
-                                                       BusTransaction *transaction,
-                                                       DBusMessage    *message,
-                                                       DBusError      *error)
+bus_driver_handle_get_connection_selinux_security_context (DBusConnection *connection,
+                                                          BusTransaction *transaction,
+                                                          DBusMessage    *message,
+                                                          DBusError      *error)
 {
   const char *service;
   DBusString str;
@@ -1052,7 +1218,7 @@ bus_driver_handle_get_connection_unix_security_context (DBusConnection *connecti
       goto failed;
     }
 
-  conn = bus_service_get_primary_owner (serv);
+  conn = bus_service_get_primary_owners_connection (serv);
 
   reply = dbus_message_new_method_return (message);
   if (reply == NULL)
@@ -1062,13 +1228,13 @@ bus_driver_handle_get_connection_unix_security_context (DBusConnection *connecti
   if (!context)
     {
       dbus_set_error (error,
-                      DBUS_ERROR_UNIX_SECURITY_CONTEXT_UNKNOWN,
+                      DBUS_ERROR_SELINUX_SECURITY_CONTEXT_UNKNOWN,
                       "Could not determine security context for '%s'", service);
       goto failed;
     }
 
-  if (! bus_selinux_append_context (reply, context))
-    goto oom;
+  if (! bus_selinux_append_context (reply, context, error))
+    goto failed;
 
   if (! bus_transaction_send_from_driver (transaction, connection, reply))
     goto oom;
@@ -1094,23 +1260,34 @@ bus_driver_handle_reload_config (DBusConnection *connection,
                                 DBusError      *error)
 {
   BusContext *context;
-  dbus_bool_t retval;
+  DBusMessage *reply;
 
   _DBUS_ASSERT_ERROR_IS_CLEAR (error);
 
-  retval = FALSE;
-
+  reply = NULL;
+  
   context = bus_connection_get_context (connection);
   if (!bus_context_reload_config (context, error))
-    {
-      _DBUS_ASSERT_ERROR_IS_SET (error);
-      goto out;
-    }
+    goto failed;
 
-  retval = TRUE;
-  
- out:
-  return retval;
+  reply = dbus_message_new_method_return (message);
+  if (reply == NULL)
+    goto oom;
+
+  if (! bus_transaction_send_from_driver (transaction, connection, reply))
+    goto oom;
+
+  dbus_message_unref (reply);
+  return TRUE;
+
+ oom:
+  BUS_SET_OOM (error);
+
+ failed:
+  _DBUS_ASSERT_ERROR_IS_SET (error);
+  if (reply)
+    dbus_message_unref (reply);
+  return FALSE;
 }
 
 /* For speed it might be useful to sort this in order of
@@ -1131,6 +1308,10 @@ struct
     DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_UINT32_AS_STRING,
     DBUS_TYPE_UINT32_AS_STRING,
     bus_driver_handle_acquire_service },
+  { "ReleaseName",
+    DBUS_TYPE_STRING_AS_STRING,
+    DBUS_TYPE_UINT32_AS_STRING,
+    bus_driver_handle_release_service },
   { "StartServiceByName",
     DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_UINT32_AS_STRING,
     DBUS_TYPE_UINT32_AS_STRING,
@@ -1159,6 +1340,10 @@ struct
     DBUS_TYPE_STRING_AS_STRING,
     DBUS_TYPE_STRING_AS_STRING,
     bus_driver_handle_get_service_owner },
+  { "ListQueuedOwners",
+    DBUS_TYPE_STRING_AS_STRING,
+    DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_STRING_AS_STRING,
+    bus_driver_handle_list_queued_owners },
   { "GetConnectionUnixUser",
     DBUS_TYPE_STRING_AS_STRING,
     DBUS_TYPE_UINT32_AS_STRING,
@@ -1167,10 +1352,10 @@ struct
     DBUS_TYPE_STRING_AS_STRING,
     DBUS_TYPE_UINT32_AS_STRING,
     bus_driver_handle_get_connection_unix_process_id },
-  { "GetConnectionUnixSecurityContext",
-    DBUS_TYPE_STRING_AS_STRING,
+  { "GetConnectionSELinuxSecurityContext",
     DBUS_TYPE_STRING_AS_STRING,
-    bus_driver_handle_get_connection_unix_security_context },
+    DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_BYTE_AS_STRING,
+    bus_driver_handle_get_connection_selinux_security_context },
   { "ReloadConfig",
     "",
     "",
@@ -1280,6 +1465,45 @@ bus_driver_handle_introspect (DBusConnection *connection,
       
       ++i;
     }
+
+  if (!_dbus_string_append_printf (&xml, "    <signal name=\"NameOwnerChanged\">\n"))
+    goto oom;
+  
+  if (!_dbus_string_append_printf (&xml, "      <arg type=\"s\"/>\n"))
+    goto oom;
+  
+  if (!_dbus_string_append_printf (&xml, "      <arg type=\"s\"/>\n"))
+    goto oom;
+  
+  if (!_dbus_string_append_printf (&xml, "      <arg type=\"s\"/>\n"))
+    goto oom;
+  
+  if (!_dbus_string_append_printf (&xml, "    </signal>\n"))
+    goto oom;
+
+
+
+  if (!_dbus_string_append_printf (&xml, "    <signal name=\"NameLost\">\n"))
+    goto oom;
+  
+  if (!_dbus_string_append_printf (&xml, "      <arg type=\"s\"/>\n"))
+    goto oom;
+  
+  if (!_dbus_string_append_printf (&xml, "    </signal>\n"))
+    goto oom;
+
+
+
+  if (!_dbus_string_append_printf (&xml, "    <signal name=\"NameAcquired\">\n"))
+    goto oom;
+  
+  if (!_dbus_string_append_printf (&xml, "      <arg type=\"s\"/>\n"))
+    goto oom;
+  
+  if (!_dbus_string_append_printf (&xml, "    </signal>\n"))
+    goto oom;
+
+
   
   if (!_dbus_string_append (&xml, "  </interface>\n"))
     goto oom;