hal: Branch 'master' - 3 commits

David Zeuthen david at kemper.freedesktop.org
Mon Feb 5 21:31:02 PST 2007


 configure.in       |   26 +--
 hald/device_info.c |   20 +-
 hald/hald_dbus.c   |  437 +++++++++++++++++++++++++++++++++++++++++++++--------
 3 files changed, 398 insertions(+), 85 deletions(-)

New commits:
diff-tree 1d1d38d1d73a5d7c26fe6adfc6cdf40a985de45b (from parents)
Merge: 429758e54aebeddb9d63b94c016b7719c5db8470 545e159e105bfaf8c0ea155e2d939f3eb1858806
Author: David Zeuthen <davidz at redhat.com>
Date:   Tue Feb 6 00:30:19 2007 -0500

    Merge branch 'master' of ssh://david@git.freedesktop.org/git/hal

diff-tree 429758e54aebeddb9d63b94c016b7719c5db8470 (from efa2758f03f41e767fd5b99385f1fc2db6984ea5)
Author: David Zeuthen <davidz at redhat.com>
Date:   Tue Feb 6 00:29:56 2007 -0500

    add optional support for ConsoleKit
    
    You have to enable this with --enable-console-kit. Right now the way
    it works is that service (e.g. methods on interfaces that is not
    org.freedesktop.Hal.Device) is denied to inactive sessions. Presently
    the main hald process denies this; going forward we will probably move
    this to specific method handlers (program being run such as Suspend()
    etc.) and add-on's.
    
    There's an easy to fix bug in pam_console on Fedora Rawhide for this
    to work out of the box on Rawhide, see
    
     https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=227462
    
    for details and how to fix it on your local system.
    
    Also, instead of asking the bus daemon for the UNIX user id of the
    caller we now cache it per connection. So there's a small optimization
    insofar that we save a roundtrip here and there.

diff --git a/configure.in b/configure.in
index a731889..7b0eb23 100644
--- a/configure.in
+++ b/configure.in
@@ -346,7 +346,7 @@ AC_DEFINE_UNQUOTED(DBUS_API_SUBJECT_TO_C
 
 # check for PolicyKit
 AM_CONDITIONAL(HAVE_POLKIT, false)
-AC_ARG_ENABLE(policy-kit, [  --disable-policy-kit    Build without PolicyKit (strongly discouraged)])
+AC_ARG_ENABLE(policy-kit, [  --enable-policy-kit     Use PolicyKit],enable_policy_kit=$enableval,enable_policy_kit=no)
 msg_polkit=no
 if test "x$enable_policy_kit" != "xno"; then
 	PKG_CHECK_MODULES(POLKIT, polkit >= 0.2,
@@ -361,6 +361,16 @@ if test "x$enable_policy_kit" != "xno"; 
 	fi
 fi
 
+# check for ConsoleKit
+AM_CONDITIONAL(HAVE_CONKIT, false)
+AC_ARG_ENABLE(console-kit, [  --enable-console-kit    Use ConsoleKit],enable_console_kit=$enableval,enable_console_kit=no)
+msg_conkit=no
+if test "x$enable_console_kit" != "xno"; then
+   AM_CONDITIONAL(HAVE_CONKIT, true)
+   AC_DEFINE(HAVE_CONKIT, [], [Set if we use ConsoleKit])
+   msg_conkit=yes
+fi
+
 # what extra hotplug backends to use (ACPI, APM, PMU etc)
 AC_ARG_ENABLE(have_acpi, [  --disable-acpi          Build without ACPI support])
 msg_acpi=no
@@ -602,7 +612,7 @@ elif test "x$with_macbookpro" = "x" ; th
 fi
 AM_CONDITIONAL(BUILD_MACBOOKPRO, test x$BUILD_MACBOOKPRO = xyes)
 
-AC_ARG_WITH(nokia770,     [  --with-nokia770       Whether to build Nokia 770 utils (no)])
+AC_ARG_WITH(nokia770,     [  --with-nokia770         Whether to build Nokia 770 utils (no)])
 BUILD_N770=no
 if test "x$with_nokia770" = "xyes"; then
     BUILD_N770=yes
@@ -751,6 +761,7 @@ echo "
         use libpci:                 ${USE_LIBPCI}
         use libparted:              ${USE_PARTED}
         use PolicyKit:              ${msg_polkit}
+        use ConsoleKit:             ${msg_conkit}
         use ACPI:                   ${msg_acpi}
         use PMU:                    ${msg_pmu}
         use APM:                    ${msg_apm}
@@ -774,17 +785,6 @@ if test x$enable_verbose_mode = xyes; th
    echo
 fi
 
-if test x$msg_polkit = xno; then
-   echo "NOTE: WARNING! WARNING! WARNING! PolicyKit is not enabled. HAL will "
-   echo "      allow any user to invoke any method. THIS IS A SECURITY RISK. "
-   echo "      Use this only if you really know what you are doing. Bugs, "
-   echo "      security issues and similar filed against HAL versions built"
-   echo "      without PolicyKit may be ignored by the HAL maintainers."
-   echo
-   echo "      Disable PolicyKit usage only if you really know what you are doing."
-   echo
-fi
-
 # (distro-tweaks required)
 if test x$with_os_type = xredhat; then
    echo "NOTE: Red Hat style init scripts and policy will be installed"
diff --git a/hald/hald_dbus.c b/hald/hald_dbus.c
index 4c93ea3..ddd6b8e 100644
--- a/hald/hald_dbus.c
+++ b/hald/hald_dbus.c
@@ -903,13 +903,236 @@ device_get_all_properties (DBusConnectio
 	return DBUS_HANDLER_RESULT_HANDLED;
 }
 
+typedef struct {
+	uid_t  uid;                   /* uid of caller */
+#ifdef HAVE_CONKIT
+	pid_t  pid;                   /* process ID of caller */
+	gboolean in_active_session;   /* caller is in an active session */
+	char *session_objpath;        /* obj path of ConsoleKit session */
+#endif
+	char *system_bus_unique_name; /* unique name of caller on the system bus */
+} CallerInfo;
+
+static CallerInfo *
+caller_info_new (void)
+{
+	CallerInfo *ci;
+	ci = g_new0 (CallerInfo, 1);
+	return ci;
+}
+
+static void 
+caller_info_free (CallerInfo *ci)
+{
+#ifdef HAVE_CONKIT
+	g_free (ci->session_objpath);
+#endif
+	g_free (ci->system_bus_unique_name);
+	g_free (ci);
+}
+
+GHashTable *connection_name_to_caller_info;
+
+static void
+ci_tracker_init (void)
+{
+	connection_name_to_caller_info = g_hash_table_new_full (g_str_hash,
+								g_str_equal,
+								NULL, /* a pointer to a CallerInfo object */
+								(GFreeFunc) caller_info_free);
+}
+
+static void 
+ci_tracker_name_owner_changed (const char *name, const char *old_service_name, const char *new_service_name)
+{
+	if (strlen (old_service_name) > 0) {
+		CallerInfo *caller_info;
+
+		/* evict CallerInfo from cache */
+		caller_info = (CallerInfo *) g_hash_table_lookup (connection_name_to_caller_info, 
+								  old_service_name);
+		if (caller_info != NULL) {
+			g_hash_table_remove (connection_name_to_caller_info, old_service_name);
+			HAL_INFO (("Removing CallerInfo object for %s", old_service_name));
+		}
+	}
+}
+
+#ifdef HAVE_CONKIT
+static void
+ci_tracker_set_active (gpointer key, gpointer value, gpointer user_data)
+{
+	CallerInfo *ci = (CallerInfo*) value;
+	char *session_objpath = (char *) user_data;
+
+	if (ci->session_objpath != NULL && strcmp (ci->session_objpath, session_objpath) == 0) {
+		ci->in_active_session = TRUE;
+		HAL_INFO (("Set in_active_session=TRUE in CallerInfo for %s @ %s (uid %d, pid %d)",
+			   ci->system_bus_unique_name, ci->session_objpath, ci->uid, ci->pid));
+	}
+}
+
+static void
+ci_tracker_clear_active (gpointer key, gpointer value, gpointer user_data)
+{
+	CallerInfo *ci = (CallerInfo*) value;
+	char *session_objpath = (char *) user_data;
+
+	if (ci->session_objpath != NULL && strcmp (ci->session_objpath, session_objpath) == 0) {
+		ci->in_active_session = FALSE;
+		HAL_INFO (("Set in_active_session=FALSE in CallerInfo for %s @ %s (uid %d, pid %d)",
+			   ci->system_bus_unique_name, ci->session_objpath, ci->uid, ci->pid));
+	}
+}
+
+static void 
+ci_tracker_active_changed (const char *session_objpath, gboolean is_active)
+{
+	if (is_active) {
+		g_hash_table_foreach (connection_name_to_caller_info, 
+				      ci_tracker_set_active, (gpointer) session_objpath);
+	} else {
+		g_hash_table_foreach (connection_name_to_caller_info, 
+				      ci_tracker_clear_active, (gpointer) session_objpath);
+	}
+}
+#endif /* HAVE_CONKIT */
+
+static CallerInfo *
+ci_tracker_get_info (const char *system_bus_unique_name)
+{
+	CallerInfo *ci;
+	DBusError error;
+#ifdef HAVE_CONKIT
+	DBusMessage *message;
+	DBusMessage *reply;
+	DBusMessageIter iter;
+	char *dbus_session_name;
+#endif /* HAVE_CONKIT */
+	
+	ci = NULL;
+	
+	if (system_bus_unique_name == NULL)
+		goto error;
+
+	/*HAL_INFO (("========================="));
+	  HAL_INFO (("Looking up CallerInfo for system_bus_unique_name = %s", system_bus_unique_name));*/
+
+	ci = g_hash_table_lookup (connection_name_to_caller_info,
+				  system_bus_unique_name);
+	if (ci != NULL) {
+		/*HAL_INFO (("(using cached information)"));*/
+		goto got_caller_info;
+	}
+	/*HAL_INFO (("(retrieving info from system bus and ConsoleKit)"));*/
+	
+	ci = caller_info_new ();
+	ci->system_bus_unique_name = g_strdup (system_bus_unique_name);
+
+	dbus_error_init (&error);
+	ci->uid = dbus_bus_get_unix_user (dbus_connection, system_bus_unique_name, &error);
+	if (ci->uid == (unsigned long) -1 || dbus_error_is_set (&error)) {
+		HAL_WARNING (("Could not get uid for connection: %s %s", error.name, error.message));
+		dbus_error_free (&error);
+		goto error;
+	}
+
+#ifdef HAVE_CONKIT
+	message = dbus_message_new_method_call ("org.freedesktop.DBus", 
+						"/org/freedesktop/DBus/Bus",
+						"org.freedesktop.DBus",
+						"GetConnectionUnixProcessID");
+	dbus_message_iter_init_append (message, &iter);
+	dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &system_bus_unique_name);
+	dbus_error_init (&error);
+	reply = dbus_connection_send_with_reply_and_block (dbus_connection, message, -1, &error);
+	if (reply == NULL || dbus_error_is_set (&error)) {
+		HAL_WARNING (("Error doing GetConnectionUnixProcessID on Bus: %s: %s", error.name, error.message));
+		dbus_message_unref (message);
+		if (reply != NULL)
+			dbus_message_unref (reply);
+		goto error;
+	}
+	dbus_message_iter_init (reply, &iter);
+	dbus_message_iter_get_basic (&iter, &ci->pid);
+	dbus_message_unref (message);
+	dbus_message_unref (reply);
+
+	message = dbus_message_new_method_call ("org.freedesktop.ConsoleKit", 
+						"/org/freedesktop/ConsoleKit/Manager",
+						"org.freedesktop.ConsoleKit.Manager",
+						"GetSessionForUnixProcess");
+	dbus_message_iter_init_append (message, &iter);
+	dbus_message_iter_append_basic (&iter, DBUS_TYPE_UINT32, &ci->pid);
+	dbus_error_init (&error);
+	reply = dbus_connection_send_with_reply_and_block (dbus_connection, message, -1, &error);
+	if (reply == NULL || dbus_error_is_set (&error)) {
+		HAL_WARNING (("Error doing GetSessionForUnixProcess on ConsoleKit: %s: %s", error.name, error.message));
+		dbus_message_unref (message);
+		if (reply != NULL)
+			dbus_message_unref (reply);
+		/* OK, this is not a catastrophe; just means the caller is not a member of any session.. */
+		goto store_caller_info;
+	}
+	dbus_message_iter_init (reply, &iter);
+	dbus_message_iter_get_basic (&iter, &dbus_session_name);
+	ci->session_objpath = g_strdup (dbus_session_name);
+	dbus_message_unref (message);
+	dbus_message_unref (reply);
+
+	message = dbus_message_new_method_call ("org.freedesktop.ConsoleKit", 
+						ci->session_objpath,
+						"org.freedesktop.ConsoleKit.Session",
+						"IsActive");
+	dbus_error_init (&error);
+	reply = dbus_connection_send_with_reply_and_block (dbus_connection, message, -1, &error);
+	if (reply == NULL || dbus_error_is_set (&error)) {
+		HAL_WARNING (("Error doing IsActive on ConsoleKit: %s: %s", error.name, error.message));
+		dbus_message_unref (message);
+		if (reply != NULL)
+			dbus_message_unref (reply);
+		goto error;
+	}
+	dbus_message_iter_init (reply, &iter);
+	dbus_message_iter_get_basic (&iter, &ci->in_active_session);
+	dbus_message_unref (message);
+	dbus_message_unref (reply);
+	
+store_caller_info:
+#endif /* HAVE_CONKIT */
+
+	g_hash_table_insert (connection_name_to_caller_info,
+			     ci->system_bus_unique_name,
+			     ci);
+
+got_caller_info:
+	/*HAL_INFO (("system_bus_unique_name = %s", ci->system_bus_unique_name));
+	HAL_INFO (("uid                    = %d", ci->uid));
+	HAL_INFO (("pid                    = %d", ci->pid));
+	if (ci->session_objpath != NULL) {
+		HAL_INFO (("session_objpath        = %s", ci->session_objpath));
+		HAL_INFO (("in_active_session      = %d", ci->in_active_session));
+	} else {
+		HAL_INFO (("  (Caller is not in any session)"));
+	}
+	HAL_INFO (("  (keeping CallerInfo for %d connections)", g_hash_table_size (connection_name_to_caller_info)));
+	HAL_INFO (("========================="));*/
+	return ci;
+
+error:
+	/*HAL_INFO (("========================="));*/
+	if (ci != NULL)
+		caller_info_free (ci);
+	return NULL;
+}
+
+
 static dbus_bool_t 
 sender_has_privileges (DBusConnection *connection, DBusMessage *message)
 {
-	DBusError error;
-	unsigned long user_uid;
 	const char *user_base_svc;
 	dbus_bool_t ret;
+	CallerInfo *ci;
 
 	ret = FALSE;
 
@@ -921,18 +1144,15 @@ sender_has_privileges (DBusConnection *c
 
 	HAL_DEBUG (("base_svc = %s", user_base_svc));
 
-	dbus_error_init (&error);
-	user_uid = dbus_bus_get_unix_user (connection, user_base_svc, &error);
-	if (user_uid == (unsigned long) -1 || dbus_error_is_set (&error)) {
-		HAL_WARNING (("Could not get uid for connection: %s %s", error.name, error.message));
-		dbus_error_free (&error);
+	ci = ci_tracker_get_info (user_base_svc);
+	if (ci == NULL) {
 		goto out;
 	}
 
-	HAL_INFO (("uid for caller is %ld", user_uid));
+	HAL_INFO (("uid for caller is %ld", ci->uid));
 
-	if (user_uid != 0 && user_uid != geteuid()) {
-		HAL_WARNING (("uid %d is not privileged", user_uid));
+	if (ci->uid != 0 && ci->uid != geteuid()) {
+		HAL_WARNING (("uid %d is not privileged", ci->uid));
 		goto out;
 	}
 
@@ -2245,32 +2465,6 @@ reinit_dbus (gpointer user_data)
 		return TRUE;
 }
 
-static void
-service_deleted (DBusMessage *message)
-{
-	char *old_service_name;
-	char *new_service_name;
-	HalDevice *d;
-
-	if (!dbus_message_get_args (message, NULL,
-				    DBUS_TYPE_STRING, &old_service_name,
-				    DBUS_TYPE_STRING, &new_service_name,
-				    DBUS_TYPE_INVALID)) {
-		HAL_ERROR (("Invalid NameOwnerChanged signal from bus!"));
-		return;
-	}
-
-	d = g_hash_table_lookup (services_with_locks, new_service_name);
-
-	if (d != NULL) {
-		hal_device_property_remove (d, "info.locked");
-		hal_device_property_remove (d, "info.locked.reason");
-		hal_device_property_remove (d, "info.locked.dbus_name");
-
-		g_hash_table_remove (services_with_locks, new_service_name);
-	}
-}
-
 static DBusHandlerResult
 device_rescan (DBusConnection * connection, DBusMessage * message, dbus_bool_t local_interface)
 {
@@ -3074,11 +3268,11 @@ hald_exec_method_cb (HalDevice *d, guint
 }
 
 static DBusHandlerResult
-hald_exec_method (HalDevice *d, DBusConnection *connection, dbus_bool_t local_interface, 
+hald_exec_method (HalDevice *d, CallerInfo *ci, DBusConnection *connection, dbus_bool_t local_interface, 
 		  DBusMessage *message, const char *execpath)
 {
 	int type;
-	GString *stdin_str;
+	GString *stdin_str = NULL;
 	DBusMessageIter iter;
 	char *extra_env[3];
 	char uid_export[128];
@@ -3092,23 +3286,43 @@ hald_exec_method (HalDevice *d, DBusConn
 		extra_env[0] = "HAL_METHOD_INVOKED_BY_UID=0";
 		extra_env[1] = "HAL_METHOD_INVOKED_BY_SYSTEMBUS_CONNECTION_NAME=0";
 	} else {
-		const char *sender;
+
+#ifdef HAVE_CONKIT
+		/* TODO: we probably should let the handler itself decide if it wants
+		 * to service the session... by e.g. exporting some env variables
+		 * set from the CallerInfo object
+		 */
+		if (ci->uid != 0) {
+			if (ci->session_objpath == NULL) {
+				HAL_INFO (("Caller %s (uid %d, pid %d) for interface %s on exec'ed method %s for %s "
+					   "is not in any session; refusing service",
+					   dbus_message_get_sender (message), ci->uid, ci->pid, 
+					   dbus_message_get_interface (message), 
+					   dbus_message_get_member (message), 
+					   dbus_message_get_path (message)));
+				raise_permission_denied (connection, message, "Not in active session");
+				goto out;
+			}
 		
-		sender = dbus_message_get_sender (message);
-		if (sender != NULL) {
-			DBusError error;
-			unsigned long uid;
-			
-			dbus_error_init (&error);
-			uid = dbus_bus_get_unix_user (connection, sender, &error);
-			if (!dbus_error_is_set (&error)) {
-				sprintf (uid_export, "HAL_METHOD_INVOKED_BY_UID=%lu", uid);
-				extra_env[0] = uid_export;
-			} 
-			snprintf (sender_export, sizeof (sender_export), 
-				  "HAL_METHOD_INVOKED_BY_SYSTEMBUS_CONNECTION_NAME=%s", sender);
-			extra_env[1] = sender_export;
+			if (!ci->in_active_session) {
+				HAL_INFO (("Caller %s (uid %d, pid %d) for interface %s on exec'ed method %s for %s "
+					   "is not in an active session (%s); refusing service",
+					   dbus_message_get_sender (message), ci->uid, ci->pid, 
+					   dbus_message_get_interface (message), 
+					   dbus_message_get_member (message), 
+					   dbus_message_get_path (message), 
+					   ci->session_objpath));
+				raise_permission_denied (connection, message, "Not in active session");
+				goto out;
+			}
 		}
+#endif /* HAVE_CONKIT */
+		
+		sprintf (uid_export, "HAL_METHOD_INVOKED_BY_UID=%d", ci->uid);
+		extra_env[0] = uid_export;
+		snprintf (sender_export, sizeof (sender_export), 
+			  "HAL_METHOD_INVOKED_BY_SYSTEMBUS_CONNECTION_NAME=%s", dbus_message_get_sender (message));
+		extra_env[1] = sender_export;
 	}
 
 	if (extra_env[0] == NULL)
@@ -3233,7 +3447,9 @@ hald_exec_method (HalDevice *d, DBusConn
 
 	dbus_message_ref (message);
 	g_string_free (stdin_str, TRUE);
-
+#ifdef HAVE_CONKIT
+out:
+#endif
 	return DBUS_HANDLER_RESULT_HANDLED;
 
 error:
@@ -3796,6 +4012,8 @@ hald_dbus_filter_handle_methods (DBusCon
 		const char *udi;
 		const char *method;
 		const char *signature;
+		const char *caller;
+		CallerInfo *ci;
 		HalDevice *d;
 
 		/* check for device-specific interfaces that individual objects may support */
@@ -3805,6 +4023,17 @@ hald_dbus_filter_handle_methods (DBusCon
 		method = dbus_message_get_member (message);
 		signature = dbus_message_get_signature (message);
 
+		caller = dbus_message_get_sender (message);
+		if (local_interface) {
+			ci = NULL;
+		} else {
+			ci = ci_tracker_get_info (caller);
+			if (ci == NULL) {
+				HAL_ERROR (("Cannot get caller info for %s", caller));
+				goto no_caller;
+			}
+		}
+
 		d = NULL;
 
 		if (udi != NULL) {
@@ -3823,6 +4052,33 @@ hald_dbus_filter_handle_methods (DBusCon
 					DBusPendingCall *pending_call;
 					DBusMessage *copy;
 
+#ifdef HAVE_CONKIT
+					/* TODO: we probably should let the add-on itself decide if it wants
+					 * to service the session...
+					 */
+					if (!local_interface && ci->uid != 0) {
+						if (ci->session_objpath == NULL) {
+							HAL_INFO (("Caller %s (uid %d, pid %d) for interface %s on "
+								   "add-on method %s for %s is not in any session; "
+								   "refusing service",
+								   caller, ci->uid, ci->pid, interface, method,
+								   udi, ci->session_objpath));
+							raise_permission_denied (connection, message, "Not in active session");
+							return DBUS_HANDLER_RESULT_HANDLED;
+						}
+
+						if (!ci->in_active_session) {
+							HAL_INFO (("Caller %s (uid %d, pid %d) for interface %s on "
+								   "add-on method %s for %s is not in an active "
+								   "session (%s); refusing service",
+								   caller, ci->uid, ci->pid, interface, method, 
+								   udi, ci->session_objpath));
+							raise_permission_denied (connection, message, "Not in active session");
+							return DBUS_HANDLER_RESULT_HANDLED;
+						}
+					}
+#endif /* HAVE_CONKIT */
+
 					/*HAL_INFO (("forwarding method to connection 0x%x", hih->connection));*/
 
 					dbus_message_ref (message);
@@ -3886,7 +4142,8 @@ hald_dbus_filter_handle_methods (DBusCon
 
 								HAL_INFO (("OK for method '%s' with signature '%s' on interface '%s' for UDI '%s' and execpath '%s'", method, signature, interface, udi, execpath));
 
-								return hald_exec_method (d, connection, local_interface,
+								return hald_exec_method (d, ci, connection, 
+											 local_interface,
 											 message, execpath);
 							}
 							
@@ -3896,11 +4153,10 @@ hald_dbus_filter_handle_methods (DBusCon
 			}
 			
 		}
-	}
-		
+	}		
+no_caller:
 	return osspec_filter_function (connection, message, user_data);
 }
-       
 
 /** Message handler for method invocations. All invocations on any object
  *  or interface is routed through this function.
@@ -3929,12 +4185,58 @@ hald_dbus_filter_function (DBusConnectio
 	} else if (dbus_message_is_signal (message,
 					   DBUS_INTERFACE_DBUS,
 					   "NameOwnerChanged")) {
+		char *name;
+		char *old_service_name;
+		char *new_service_name;
+		HalDevice *d;
+
+		if (!dbus_message_get_args (message, NULL,
+					    DBUS_TYPE_STRING, &name,
+					    DBUS_TYPE_STRING, &old_service_name,
+					    DBUS_TYPE_STRING, &new_service_name,
+					    DBUS_TYPE_INVALID)) {
+			HAL_ERROR (("Invalid NameOwnerChanged signal from bus!"));
+			goto out;
+		}
 
-		if (services_with_locks != NULL)
-			service_deleted (message);
+		HAL_INFO (("NameOwnerChanged name=%s old=%s new=%s", name, old_service_name, new_service_name));
+
+		ci_tracker_name_owner_changed (name, old_service_name, new_service_name);
+
+		if (services_with_locks != NULL) {
+			d = g_hash_table_lookup (services_with_locks, new_service_name);
+			if (d != NULL) {
+				hal_device_property_remove (d, "info.locked");
+				hal_device_property_remove (d, "info.locked.reason");
+				hal_device_property_remove (d, "info.locked.dbus_name");
+				
+				g_hash_table_remove (services_with_locks, new_service_name);
+			}
+		}
+
+#ifdef HAVE_CONKIT
+	} else if (dbus_message_is_signal (message,
+					   "org.freedesktop.ConsoleKit.Session",
+					   "ActiveChanged")) {
+		gboolean is_active;
+		const char *session_objpath;
+
+		if (!dbus_message_get_args (message, NULL,
+					    DBUS_TYPE_BOOLEAN, &is_active,
+					    DBUS_TYPE_INVALID)) {
+			HAL_ERROR (("Invalid ActiveChanged signal from ConsoleKit!"));
+			goto out;
+		}
+
+		session_objpath = dbus_message_get_path (message);
+
+		HAL_INFO (("active=%d for session %s", is_active, session_objpath));
+		ci_tracker_active_changed (session_objpath, is_active);
+#endif /* HAVE_CONKIT */
 	} else 
 		return hald_dbus_filter_handle_methods (connection, message, user_data, FALSE);
 
+out:
 	return DBUS_HANDLER_RESULT_HANDLED;
 }
 
@@ -3945,11 +4247,11 @@ local_server_message_handler (DBusConnec
 			      DBusMessage *message, 
 			      void *user_data)
 {
-	HAL_INFO (("local_server_message_handler: destination=%s obj_path=%s interface=%s method=%s", 
+	/*HAL_INFO (("local_server_message_handler: destination=%s obj_path=%s interface=%s method=%s", 
 		   dbus_message_get_destination (message) ? dbus_message_get_destination (message) : "",
 		   dbus_message_get_path (message) ?  dbus_message_get_path (message) : "" , 
 		   dbus_message_get_interface (message) ? dbus_message_get_interface (message) : "",
-		   dbus_message_get_member (message) ? dbus_message_get_member (message) : ""));
+		   dbus_message_get_member (message) ? dbus_message_get_member (message) : ""));*/
 
 	if (dbus_message_is_method_call (message, "org.freedesktop.DBus", "AddMatch")) {
 		DBusMessage *reply;
@@ -4122,6 +4424,17 @@ hald_dbus_init (void)
 			    ",member='NameOwnerChanged'",
 			    NULL);
 
+#ifdef HAVE_CONKIT
+	dbus_bus_add_match (dbus_connection,
+			    "type='signal'"
+			    ",interface='org.freedesktop.ConsoleKit.Session'"
+			    ",sender='org.freedesktop.ConsoleKit'"
+			    ",member='ActiveChanged'",
+			    NULL);
+#endif /* HAVE_CONKIT */
+
+	ci_tracker_init ();
+
 	return TRUE;
 }
 
diff-tree efa2758f03f41e767fd5b99385f1fc2db6984ea5 (from bae149a89341750ad52a07dd27a337a1b7659ae7)
Author: David Zeuthen <davidz at redhat.com>
Date:   Mon Feb 5 23:13:13 2007 -0500

    reduce debugging spew for fdi files

diff --git a/hald/device_info.c b/hald/device_info.c
index 0dd1cdc..b69c574 100644
--- a/hald/device_info.c
+++ b/hald/device_info.c
@@ -638,7 +638,7 @@ handle_match (struct rule *rule, HalDevi
 static void
 spawned_device_callouts_add_done (HalDevice *d, gpointer userdata1, gpointer userdata2)
 {
-	HAL_INFO (("Add callouts completed udi=%s", hal_device_get_udi (d)));
+	/*HAL_INFO (("Add callouts completed udi=%s", hal_device_get_udi (d)));*/
 
 	/* Move from temporary to global device store */
 	hal_device_store_remove (hald_get_tdl (), d);
@@ -858,14 +858,14 @@ rules_match_and_merge_device (void *fdi_
 {
 	struct rule *rule = fdi_rules_list;
 	while (rule != NULL){
-		HAL_INFO(("== Iterating rules =="));
+		/*HAL_INFO(("== Iterating rules =="));*/
 
 		switch (rule->rtype) {
 		case RULE_MATCH:
 			/* skip non-matching rules block */
-			HAL_INFO(("%p match '%s' at %s", rule, rule->key, hal_device_get_udi (d)));
+			/*HAL_INFO(("%p match '%s' at %s", rule, rule->key, hal_device_get_udi (d)));*/
 			if (!handle_match (rule, d)) {
-				HAL_INFO(("no match, skip to rule (%llx)", rule->jump_position));
+				/*HAL_INFO(("no match, skip to rule (%llx)", rule->jump_position));*/
 				rule = di_jump(rule);
 
 				if(rule == NULL)
@@ -908,9 +908,9 @@ di_search_and_merge (HalDevice *d, Devic
 		/* Checking if we have at least one preprobe rule */
 		if(header->fdi_rules_information > header->fdi_rules_preprobe)
 		{
-			HAL_INFO(("preprobe rules offset: %ld", header->fdi_rules_preprobe));
+			/*HAL_INFO(("preprobe rules offset: %ld", header->fdi_rules_preprobe));
 			HAL_INFO(("preprobe rules size: %ld",
-				header->fdi_rules_information - header->fdi_rules_preprobe));
+			header->fdi_rules_information - header->fdi_rules_preprobe));*/
 			rules_match_and_merge_device (RULES_PTR(header->fdi_rules_preprobe), d);
 		}
 		break;
@@ -919,9 +919,9 @@ di_search_and_merge (HalDevice *d, Devic
 		/* Checking if we have at least one information rule */
 		if(header->fdi_rules_policy > header->fdi_rules_information)
 		{
-			HAL_INFO(("information rules offset: %ld", header->fdi_rules_information));
+			/*HAL_INFO(("information rules offset: %ld", header->fdi_rules_information));
 			HAL_INFO(("information rules size: %ld",
-				header->fdi_rules_policy - header->fdi_rules_information));
+			header->fdi_rules_policy - header->fdi_rules_information));*/
 			rules_match_and_merge_device (RULES_PTR(header->fdi_rules_information), d);
 		}
 		break;
@@ -930,9 +930,9 @@ di_search_and_merge (HalDevice *d, Devic
 		/* Checking if we have at least one policy rule */
 		if(header->all_rules_size > header->fdi_rules_policy)
 		{
-			HAL_INFO(("policy rules offset: %ld", header->fdi_rules_policy));
+			/*HAL_INFO(("policy rules offset: %ld", header->fdi_rules_policy));
 			HAL_INFO(("policy rules size: %ld",
-				header->all_rules_size - header->fdi_rules_policy));
+			header->all_rules_size - header->fdi_rules_policy));*/
 			rules_match_and_merge_device (RULES_PTR(header->fdi_rules_policy), d);
 		}
 		break;


More information about the hal-commit mailing list