bus_registry_acquire_service: remove unnecessary variable
[platform/upstream/dbus.git] / bus / services.c
index bb7e77f..68a7022 100644 (file)
@@ -1,4 +1,4 @@
-/* -*- mode: C; c-file-style: "gnu" -*- */
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
 /* services.c  Service management
  *
  * Copyright (C) 2003  Red Hat, Inc.
  * 
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  *
  */
+
+#include <config.h>
 #include <dbus/dbus-hash.h>
 #include <dbus/dbus-list.h>
 #include <dbus/dbus-mempool.h>
@@ -383,7 +385,6 @@ bus_registry_acquire_service (BusRegistry      *registry,
 {
   dbus_bool_t retval;
   DBusConnection *old_owner_conn;
-  DBusConnection *current_owner_conn;
   BusClientPolicy *policy;
   BusService *service;
   BusActivation  *activation;
@@ -417,6 +418,18 @@ bus_registry_acquire_service (BusRegistry      *registry,
       goto out;
     }
 
+  if (_dbus_string_equal_c_str (service_name, DBUS_SERVICE_DBUS))
+    {
+      dbus_set_error (error, DBUS_ERROR_INVALID_ARGS,
+                      "Connection \"%s\" is not allowed to own the service \"%s\"because "
+                      "it is reserved for D-Bus' use only",
+                      bus_connection_is_active (connection) ?
+                      bus_connection_get_name (connection) :
+                      "(inactive)",
+                      DBUS_SERVICE_DBUS);
+      goto out;
+    }
+
   policy = bus_connection_get_policy (connection);
   _dbus_assert (policy != NULL);
 
@@ -445,7 +458,7 @@ bus_registry_acquire_service (BusRegistry      *registry,
                       _dbus_string_get_const_data (service_name));
       goto out;
     }
-      
+  
   if (!bus_client_policy_check_can_own (policy, connection,
                                         service_name))
     {
@@ -496,12 +509,10 @@ 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 (current_owner_conn == connection);
+      _dbus_assert (primary_owner->conn == connection);
 
       *result = DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER;      
     }
@@ -623,6 +634,19 @@ bus_registry_release_service (BusRegistry      *registry,
       goto out;
     }
 
+   if (_dbus_string_equal_c_str (service_name, DBUS_SERVICE_DBUS))
+    {
+      /* Not allowed; the base service name cannot be created or released */
+      dbus_set_error (error, DBUS_ERROR_INVALID_ARGS,
+                      "Cannot release the %s service because it is owned by the bus",
+                     DBUS_SERVICE_DBUS);
+
+      _dbus_verbose ("Attempt to release service name \"%s\"",
+                     DBUS_SERVICE_DBUS);
+
+      goto out;
+    }
+
   service = bus_registry_lookup (registry, service_name);
 
   if (service == NULL)