gdm r5631 - in trunk: . gui/simple-greeter



Author: mccann
Date: Thu Jan 24 04:09:53 2008
New Revision: 5631
URL: http://svn.gnome.org/viewvc/gdm?rev=5631&view=rev

Log:
2008-01-23  William Jon McCann  <mccann jhu edu>

	* gui/simple-greeter/gdm-greeter-login-window.c:
	(get_action_from_error), (do_system_restart), (do_system_stop):
	Don't try to determine PK action independently.  Parse
	it from the error message.



Modified:
   trunk/ChangeLog
   trunk/gui/simple-greeter/gdm-greeter-login-window.c

Modified: trunk/gui/simple-greeter/gdm-greeter-login-window.c
==============================================================================
--- trunk/gui/simple-greeter/gdm-greeter-login-window.c	(original)
+++ trunk/gui/simple-greeter/gdm-greeter-login-window.c	Thu Jan 24 04:09:53 2008
@@ -478,163 +478,6 @@
 }
 
 static gboolean
-get_int (DBusGProxy *proxy,
-         const char *method,
-         int        *val)
-{
-        GError  *error;
-        gboolean res;
-
-        error = NULL;
-        res = dbus_g_proxy_call (proxy,
-                                 method,
-                                 &error,
-                                 G_TYPE_INVALID,
-                                 G_TYPE_INT, val,
-                                 G_TYPE_INVALID);
-        if (! res) {
-                g_warning ("%s failed: %s", method, error->message);
-                g_error_free (error);
-        }
-
-        return res;
-}
-
-static gboolean
-get_string (DBusGProxy *proxy,
-            const char *method,
-            char      **str)
-{
-        GError  *error;
-        gboolean res;
-
-        error = NULL;
-        res = dbus_g_proxy_call (proxy,
-                                 method,
-                                 &error,
-                                 G_TYPE_INVALID,
-                                 G_TYPE_STRING, str,
-                                 G_TYPE_INVALID);
-        if (! res) {
-                g_warning ("%s failed: %s", method, error->message);
-                g_error_free (error);
-        }
-
-        return res;
-}
-
-static char *
-get_user_name (uid_t uid)
-{
-        struct passwd *pwent;
-        char          *name;
-
-        name = NULL;
-
-        pwent = getpwuid (uid);
-
-        if (pwent != NULL) {
-                name = g_strdup (pwent->pw_name);
-        }
-
-        return name;
-}
-
-static gboolean
-session_is_real_user (DBusGConnection *connection,
-                      const char      *ssid)
-{
-        DBusGProxy *proxy;
-        int         uid;
-        char       *username;
-        char       *session_type;
-        gboolean    ret;
-
-        ret = FALSE;
-        session_type = NULL;
-        username = NULL;
-
-        proxy = dbus_g_proxy_new_for_name (connection,
-                                           CK_NAME,
-                                           ssid,
-                                           CK_SESSION_INTERFACE);
-        if (proxy == NULL) {
-                return FALSE;
-        }
-
-        session_type = NULL;
-
-        get_int (proxy, "GetUnixUser", &uid);
-        get_string (proxy, "GetSessionType", &session_type);
-
-        username = get_user_name (uid);
-
-        /* filter out GDM user */
-        if (username != NULL && strcmp (username, "gdm") == 0) {
-                ret = FALSE;
-                goto out;
-        }
-
-        ret = TRUE;
-
- out:
-        g_free (username);
-        g_free (session_type);
-        g_object_unref (proxy);
-
-        return ret;
-}
-
-static guint
-get_system_num_sessions (DBusGConnection *connection)
-{
-        DBusGProxy      *proxy;
-        gboolean         res;
-        GPtrArray       *sessions;
-        guint            num_sessions;
-        GError          *error;
-        int              i;
-
-        proxy = dbus_g_proxy_new_for_name (connection,
-                                           CK_NAME,
-                                           CK_MANAGER_PATH,
-                                           CK_MANAGER_INTERFACE);
-        error = NULL;
-        res = dbus_g_proxy_call_with_timeout (proxy,
-                                              "GetSessions",
-                                              INT_MAX,
-                                              &error,
-                                              /* parameters: */
-                                              G_TYPE_INVALID,
-                                              /* return values: */
-                                              dbus_g_type_get_collection ("GPtrArray", DBUS_TYPE_G_OBJECT_PATH),
-                                              &sessions,
-                                              G_TYPE_INVALID);
-        if (! res) {
-                g_warning ("Unable to query sessions: %s", error->message);
-                g_error_free (error);
-                return 0;
-        }
-
-        num_sessions = 0;
-        for (i = 0; i < sessions->len; i++) {
-                char *ssid;
-
-                ssid = g_ptr_array_index (sessions, i);
-
-                if (session_is_real_user (connection, ssid)) {
-                        num_sessions++;
-                }
-
-                g_free (ssid);
-        }
-
-        g_ptr_array_free (sessions, TRUE);
-
-        return num_sessions;
-}
-
-static gboolean
 try_system_stop (DBusGConnection *connection,
                  GError         **error)
 {
@@ -752,6 +595,25 @@
         }
 }
 
+static PolKitAction *
+get_action_from_error (GError *error)
+{
+        PolKitAction *action;
+        const char   *paction;
+
+        action = polkit_action_new ();
+
+        paction = NULL;
+        if (g_str_has_prefix (error->message, "Not privileged for action: ")) {
+                paction = error->message + strlen ("Not privileged for action: ");
+        }
+        g_debug ("Requesting priv for '%s'", paction);
+
+        polkit_action_set_action_id (action, paction);
+
+        return action;
+}
+
 static void
 do_system_restart (GdmGreeterLoginWindow *login_window)
 {
@@ -777,22 +639,12 @@
                         PolKitAction *action;
                         guint         xid;
                         pid_t         pid;
-                        const char   *paction;
+
+                        action = get_action_from_error (error);
 
                         xid = 0;
                         pid = getpid ();
 
-                        action = polkit_action_new ();
-                        if (get_system_num_sessions (connection) > 1) {
-                                paction = "org.freedesktop.consolekit.system.restart-multiple-sessions";
-                        } else {
-                                paction = "org.freedesktop.consolekit.system.restart";
-                        }
-                        polkit_action_set_action_id (action, paction);
-
-                        g_debug ("GdmGreeterLoginWindow: trying to obtain authorization for %s",
-                                 paction);
-
                         g_error_free (error);
                         error = NULL;
                         res = polkit_gnome_auth_obtain (action,
@@ -838,21 +690,11 @@
                         PolKitAction *action;
                         guint         xid;
                         pid_t         pid;
-                        const char   *paction;
 
                         xid = 0;
                         pid = getpid ();
 
-                        action = polkit_action_new ();
-                        if (get_system_num_sessions (connection) > 1) {
-                                paction = "org.freedesktop.consolekit.system.stop-multiple-sessions";
-                        } else {
-                                paction = "org.freedesktop.consolekit.system.stop";
-                        }
-                        polkit_action_set_action_id (action, paction);
-
-                        g_debug ("GdmGreeterLoginWindow: trying to obtain authorization for %s",
-                                 paction);
+                        action = get_action_from_error (error);
 
                         g_error_free (error);
                         error = NULL;



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