[vdagent-linux v4 7/7] console-kit: implement check for session type

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 67 insertions(+), 2 deletions(-)

diff --git a/src/console-kit.c b/src/console-kit.c
index 489dd61..024a260 100644
--- a/src/console-kit.c
+++ b/src/console-kit.c
@@ -505,8 +505,73 @@ gboolean session_info_session_is_locked(struct session_info *info)
     return locked;
 }
 
+/* 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 *info)
 {
-    /* TODO */
-    return TRUE;
+    DBusError error;
+    DBusMessage *message = NULL;
+    DBusMessage *reply = NULL;
+    gchar *session_type = NULL;
+    gboolean ret = TRUE;
+
+    g_return_val_if_fail (info != NULL, TRUE);
+    g_return_val_if_fail (info->connection != NULL, TRUE);
+    g_return_val_if_fail (info->active_session != NULL, TRUE);
+
+    message = dbus_message_new_method_call(INTERFACE_CONSOLE_KIT,
+                                           info->active_session,
+                                           INTERFACE_CONSOLE_KIT_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(info->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 (info->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

_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/spice-devel




[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]     [Monitors]