[Spice-devel] [vdagent-linux v2 5/5] console-kit: implement check for session type
Victor Toso
victortoso at redhat.com
Sat Apr 23 10:53:17 UTC 2016
Implementing the function that was introduced in previous commit:
session_info_is_user()
In console-kit we can gather the session type with GetSessionType api from
Session interface. This function is not well documented but seems reliable
enough as GDM was using it [0]
[0] session_is_login_window on gui/simple-greeter/gdm-user-manager.c
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1323640
---
src/console-kit.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 66 insertions(+), 2 deletions(-)
diff --git a/src/console-kit.c b/src/console-kit.c
index 0ee79bf..fb3a022 100644
--- a/src/console-kit.c
+++ b/src/console-kit.c
@@ -501,8 +501,72 @@ gboolean session_info_session_is_locked(struct session_info *si)
return (si->session_is_locked || si->session_idle_hint);
}
+/* This function should only be called after session_info_get_active_session
+ * in order to verify if active session belongs to user (non greeter) */
gboolean session_info_is_user(struct session_info *si)
{
- /* TODO */
- return TRUE;
+ DBusError error;
+ DBusMessage *message;
+ DBusMessage *reply;
+ gchar *session_type = NULL;
+ gboolean ret = TRUE;
+
+ if (si == NULL || si->connection == NULL || si->active_session == NULL)
+ return TRUE;
+
+ message = dbus_message_new_method_call(INTERFACE_CONSOLE_KIT,
+ si->active_session,
+ INTERFACE_CK_SESSION,
+ "GetSessionType");
+ if (message == NULL) {
+ syslog(LOG_ERR,
+ "(console-kit) Unable to create dbus message for GetSessionType");
+ return TRUE;
+ }
+
+ dbus_error_init(&error);
+ reply = dbus_connection_send_with_reply_and_block(si->connection,
+ message,
+ -1,
+ &error);
+ if (reply == NULL || dbus_error_is_set(&error)) {
+ if (dbus_error_is_set(&error)) {
+ syslog(LOG_ERR, "GetSessionType failed: %s", error.message);
+ dbus_error_free(&error);
+ } else
+ syslog(LOG_ERR, "GetSessionType failed");
+ goto exit;
+ }
+
+ dbus_error_init(&error);
+ if (!dbus_message_get_args(reply,
+ &error,
+ DBUS_TYPE_STRING, &session_type,
+ DBUS_TYPE_INVALID)) {
+ if (dbus_error_is_set(&error)) {
+ syslog(LOG_ERR,
+ "(console-kit) fail to get session-type from reply: %s",
+ error.message);
+ dbus_error_free(&error);
+ } else {
+ syslog(LOG_ERR, "(console-kit) fail to get session-type from reply");
+ }
+ session_type = NULL;
+ goto exit;
+ }
+
+ /* Empty session_type means user */
+ if (si->verbose)
+ syslog(LOG_DEBUG, "(console-kit) session-type is '%s'", session_type);
+
+ ret = (g_strcmp0 (session_type, "LoginWindow") != 0);
+
+exit:
+ if (reply != NULL) {
+ dbus_message_unref(reply);
+ }
+ if (message != NULL) {
+ dbus_message_unref(message);
+ }
+ return ret;
}
--
2.5.5
More information about the Spice-devel
mailing list